Boilerplate Flask app that is portable between different serverless platforms.
Deployment and application code adaptors are being added for the following:
Platform | Deployment | Status |
---|---|---|
AWS Lambda | AWS SAM | ✔️ |
AWS Lambda | Terraform | ✔️ |
Azure Functions | Terraform | |
Google Cloud Functions | Terraform | |
Google Kubernetes Engine | gcloud & kubectl |
Platform | Adaptor | Code/Config |
---|---|---|
Local Development | None | 💾 |
AWS Lambda Python >= 3.6 | Flask-Lambda-Python36 | 💾 |
AWS Lambda Python <= 3.6 | Flask-Lambda | 💾 |
Azure Functions | ||
Google Cloud Functions |
This is used to set the environment variables required for deployment and local development.
$ cp .env.example .env
$ vim .env
$ make env
$ source env/bin/activate
$ make deps
Ensure you have created your virtualenv and have the necessary environment variables set (see setup instructions above).
$ source env/bin/activate
$ source .env
$ make server-debug
$ docker-compose up
$ http-prompt localhost:5000
GET /artists
Ensure you have created your virtualenv and have the necessary environment variables set (see setup instructions above).
Create terraform state bucket.
$ aws s3 mb --region eu-west-2 s3://<bucket_name>
Update bucket name in /terraform/main.tf
.
terraform {
backend "s3" {
bucket = "<bucket_name>"
key = "terraform.tfstate"
region = "eu-west-2"
}
}
Bundle the app into a zip and deploy it using terraform.
$ ./bin/deploy
$ http-prompt $(cd terraform && terraform output api_url)
GET artists
AWS Serverless Application Model (SAM) Deployment
Unlike Terraform SAM doesn't upload the zip bundle so do this using the aws-cli
tool.
$ aws s3 mb s3://<mybucket>
$ aws s3 cp terraform/dist/python-serverless-api.zip s3://<mybucket>/python-serverless-api.zip
Update the S3 bucket value in the SAM config.
# template.yaml
AWSTemplateFormatVersion: '2010-09-09'
Transform: 'AWS::Serverless-2016-10-31'
Description: 'Boilerplate Python 3.6 Flask App.'
Resources:
FlaskAPI:
Type: 'AWS::Serverless::Function'
Properties:
CodeUri: s3://<mybucket>/flask-app.zip
Deploy the SAM template with Cloudformation.
$ aws cloudformation deploy \
--template-file template.yaml \
--stack-name python-serverless-stack-sam
--capabilities CAPABILITY_IAM
$ make test
$ make lint