From 7524066a097c3305e4147199547ab7dee64b8a64 Mon Sep 17 00:00:00 2001 From: Tom Kralidis Date: Wed, 4 Sep 2019 09:34:32 -0400 Subject: [PATCH] add README and zappa example for AWS Lambda --- aws-lambda/README.md | 47 +++++++++++++++++++++++++++++----- aws-lambda/zappa_settings.json | 14 ++++++++++ 2 files changed, 55 insertions(+), 6 deletions(-) create mode 100644 aws-lambda/zappa_settings.json diff --git a/aws-lambda/README.md b/aws-lambda/README.md index 880c20f..532060f 100644 --- a/aws-lambda/README.md +++ b/aws-lambda/README.md @@ -1,6 +1,41 @@ -# USING PyGeoAPI on AWS Lambda Serverless +# Using pygeoapi on AWS Lambda Serverless -The included serverless.yml and pygeoapi-serverless-config.yml can be used to deploy PyGeoAPI +## Overview + +AWS Lambda Serverless is a service from Amazon that enables publishing +code which is executed as on demand functions. The value is here is that +the server is only working when requests are made, resulting in more efficient +use of server resources as well as managing costs. + +pygeoapi provides a couple of ways to publish to AWS Lambda depending on your +environment: zappa and node/serverless. + +## zappa + +[zappa](https://www.zappa.io) provides Python tooling to interact with AWS lambda. Ensure the environment +variables `AWS_ACCESS_KEY` and `AWS_SECRET_ACCESS_KEY` are set and available. + +```bash +# install zappa +pip install zappa + +# set environment variables +export AWS_ACCESS_KEY_ID=foo +export AWS_SECRET_ACCESS_KEY=bar + +# deploy pygeoapi to AWS Lambda +zappa deploy -s zappa_settings.json + +# update +zappa update -s zappa_settings.json + +# undeploy +zappa undeploy -s zappa_settings.json +``` + +## node/serverless + +The included `serverless.yml` and `pygeoapi-serverless-config.yml` can be used to deploy pygeoapi on AWS Lambda Serverless Environment. This requires Amazon Credentials and the Serverless deployment tool. @@ -9,26 +44,26 @@ AWS Credentials can be created following the instructions at https://serverless. To install the Serverless environment -```shell +```bash npm install serverless ``` The following serverless plugins are also used -``` +```bash serverless plugin install -n serverless-python-requirements serverless plugin install -n serverless-wsgi ``` To deploy to AWS Lambda: -``` +```bash serverless deploy ``` Once deployed, if you only need to update the code and not anything in the serverless configuration, you can update the function using: -``` +```bash serverless deploy --function app ``` diff --git a/aws-lambda/zappa_settings.json b/aws-lambda/zappa_settings.json new file mode 100644 index 0000000..d17c87b --- /dev/null +++ b/aws-lambda/zappa_settings.json @@ -0,0 +1,14 @@ +{ + "dev": { + "app_function": "pygeoapi.flask_app.APP", + "profile_name": null, + "project_name": "pygeoapi", + "runtime": "python3.6", + "s3_bucket": "zappa-pwpqh2twb", + "aws_region": "us-east-2" + "environment_variables": { + "PYGEOAPI_CONFIG": "pygeoapi-config.yml" + "PYGEOAPI_OPENAPI": "pygeoapi-openapi.yml" + } + } +}