Chalice GIS Demo https://github.com/mikequentel/chalice-gis-demo
- 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.
- 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
- Connection to database: psycopg2
- Circle distance calculation uses the libraries geographiclib and geopy
- 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
- Select top (limit) of items /restaurants/limit/{limit} eg: https://a4fpsm6md0.execute-api.us-east-1.amazonaws.com/api/restaurants/limit/100
- Select by object ID /restaurants/oid/{oid} eg: https://a4fpsm6md0.execute-api.us-east-1.amazonaws.com/api/restaurants/oid/1441071
- Select by circle (items within the circle), with parameters latitude, longitude, and radius in km /restaurants/circle/{circle} eg: https://a4fpsm6md0.execute-api.us-east-1.amazonaws.com/api/restaurants/circle/43.1009,-75.2327,150.5
- Select by bounding box (items within bounding box), with parameters upper left latitude, upper left longitude, lower right latitude, lower right longitude /restaurants/bbox/{bbox} eg: https://a4fpsm6md0.execute-api.us-east-1.amazonaws.com/api/restaurants/bbox/43.000000,-79.000000,41.000000,-71.000000
- Select by facility (restaurant) name /restaurants/facility/{facility} eg: https://a4fpsm6md0.execute-api.us-east-1.amazonaws.com/api/restaurants/facility/LITTLE%20ROMA%20PIZZA,%20INC%2E
- Select by county containing facilities of interest /restaurants/county/{county} eg: https://a4fpsm6md0.execute-api.us-east-1.amazonaws.com/api/restaurants/county/ONEIDA
- 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.
- PostgreSQL
- Python (version 2.7 was used for the demo but you could use 3 instead)
- Pip
- Virtualenv
- Chalice
- Clone the Git repository:
git clone https://github.com/mikequentel/chalice-gis-demo.git
- Enable the Virtual Environment (via
virtualenv
):pip install -r requirements.txt
- Install a local copy of the database
businesses
which contains the tablerestaurants
by using the plain text dumpdata/businesses_backup.sql
--example: assuming database namedbusinesses
already exists (that is, you already created the database), then for userpostgres
, run the command:psql -U postgres -h localhost --set ON_ERROR_STOP=on businesses < businesses_backup.sql
- Set the appropriate credentials, which set environment variables used to connect to the database, in the file
.chalice/config.json
- Start the server locally by running
chalice local
which will deploy the server to http://localhost:8000 - Now, you can run queries against the server through any HTTP client, but most easily through using the example at
client/map.html
- Account at Amazon Web Services
- Strongly advise that you create an IAM admin account and use it for day-to-day administrative tasks instead of the root account (root account is typically used for initial set up and billing/account settings).
- Private keys (typically installed at
~/.aws
) -- see the following for how to set up this:
- Create an AWS RDS database and load it with a PostgreSQL dump (such as the SQL file at
data/businesses_backup.sql
). - Modify the credentials for Chalice at
.chalice/config.json
- Deploy the demo using the command
chalice deploy
- 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
- 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.