mikequentel / chalice-gis-demo

FaaS REST GIS in AWS

Home Page:https://www.linkedin.com/pulse/create-faas-rest-gis-aws-using-open-source-tools-mike-quentel

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

chalice-gis-demo client

  • A reference implementation of a REST-exposed GIS server using AWS Lambda functions generated using Chalice. Includes AWS features such as RDS (for the PostgreSQL database), Lambda (for the FaaS modules), API Gateway for handling requests and responses, VPC (Virtual Private Cloud) which enables proper performance between Lambda and RDS. It is a proof-of-concept and a demo of how one can implement a FaaS GIS server into AWS. It is not meant to be a robust, production-quality solution, but rather an example and potential starting point for future projects.
  • Article describing this proof-of-concept: Create a FaaS REST GIS in AWS using Open Source Tools
  • Lambda framework: Chalice
  • Database: PostgreSQL
    • Based on restaurant inspection data, from several years ago (circa 2013), collected by the state of New York and shared at the USA government website data.gov
      • This is publicly available information published by the US government.
    • The backend database for this demo does not include PostGIS at this time.
    • Contains a flat table named restaurants--not a normalised database, for simplicity of the demo.
  • Connection to database: psycopg2
  • Circle distance calculation uses the libraries geographiclib and geopy

Interfaces

Note about the REST interfaces

  • At this time, the interfaces are GET (read-only) actions, especially since the proof-of-concept is being publicly hosted.
  • The documentation for Chalice framework includes information on how to include other REST operations such as POST, PUT, and DELETE

Examples of included interfaces--one exists for each field in the database.

Published on swaggerhub

  • Published at: https://app.swaggerhub.com/apis/9902350canada/restaurants/1.0
  • Swagger was not used to create the API, but nevertheless the API has been published as an FYI at swaggerhub.com from swagger/chalice-gis-demo-api-swagger.yaml which was exported from AWS API Gateway.
  • You can ignore the semantic error messages at swaggerhub.com and successfully run tests against the API.

Hacking

Prerequisites

  • PostgreSQL
  • Python (version 2.7 was used for the demo but you could use 3 instead)
  • Pip
  • Virtualenv
  • Chalice

Steps

  1. Clone the Git repository: git clone https://github.com/mikequentel/chalice-gis-demo.git
  2. Enable the Virtual Environment (via virtualenv): pip install -r requirements.txt
  3. Install a local copy of the database businesses which contains the table restaurants by using the plain text dump data/businesses_backup.sql--example: assuming database named businesses already exists (that is, you already created the database), then for user postgres, run the command: psql -U postgres -h localhost --set ON_ERROR_STOP=on businesses < businesses_backup.sql
  4. Set the appropriate credentials, which set environment variables used to connect to the database, in the file .chalice/config.json
  5. Start the server locally by running chalice local which will deploy the server to http://localhost:8000
  6. Now, you can run queries against the server through any HTTP client, but most easily through using the example at client/map.html

Deploying to AWS

Prerequisites

Steps

  1. Create an AWS RDS database and load it with a PostgreSQL dump (such as the SQL file at data/businesses_backup.sql).
  2. Modify the credentials for Chalice at .chalice/config.json
  3. Deploy the demo using the command chalice deploy
  4. Create a VPC to enable a connection between the resulting AWS Lambda and the RDS. Only need to set this up once. The RDS can be publically accessible but needs the VPC for proper performance; otherwise, the Lambda functions will time-out when attempting to call them through AWS API Gateway. If you are having configuration issues with the VPC and RDS, please see Troubleshoot Issues Connecting to an RDS Instance
  5. The example client can also be deployed to AWS. I recommend using AWS S3 bucket to host a static web page (eg: client/map.html), and be sure to CORS-enable the bucket.

About

FaaS REST GIS in AWS

https://www.linkedin.com/pulse/create-faas-rest-gis-aws-using-open-source-tools-mike-quentel

License:MIT License


Languages

Language:Python 76.2%Language:HTML 17.8%Language:Shell 6.0%