cdk-python-web-apps
Python based Web apps, built with custom Docker containers, deployed to AWS with CDK.
What is this for?
This repository details ways to deploy Python Web frameworks (e.g. Flask) as standalone functions with AWS CDK. Connections to the applications are proxied through API Gateway.
Getting started
For up to date info see the AWS CDK getting started guide.
npm install -g aws-cdk
- Activate a python virtual environment and install the CDK dependencies. (Using pyenv)
pyenv virtualenv 3.9.11 awscdk
pyenv local awscdk
pip install --upgrade pip
pip install -r requirements.txt
cdk bootstrap aws://ACCOUNT-NUMBER/REGION
(e.g. cdk bootstrap aws://1234567890/us-east-1)- Make sure Docker is installed and running.
Manifest
- Lambda + Python 3.9 + Flask 2.x
- Lambda + Python 3.9 + FastAPI
- ECS Fargate + Python 3.10 + Flask 2.x
- Lambda + Python 3.11 + Flask 2.x
- Lambda + Python 3.11 + FastAPI
- Lambda + Python 3.11 + Django 4.1
Deploy
# Deploy all at once
cdk deploy --require-approval never --all --concurrency 5 --profile <your AWS profile>
# Individual app deployment
cdk deploy --require-approval never CdkLambdaPython39Flask --profile <your AWS profile>
cdk deploy --require-approval never CdkLambdaPython39FastAPI --profile <your AWS profile>
cdk deploy --require-approval never CdkEcsFargatePython310Flask --profile <your AWS profile>
cdk deploy --require-approval never CdkLambdaPython311Flask --profile <your AWS profile>
cdk deploy --require-approval never CdkLambdaPython311FastAPI --profile <your AWS profile>
cdk deploy --require-approval never CdkLambdaPython311Django --profile <your AWS profile>
Destroy
yes | cdk destroy --all
Note: Instructions and configurations were built on MacOS 12.3.x with an M1 processor. Docker commands and containers were built for platform: linux/amd64
.