Example of building and running Flask web application on AWS Lambda using AWS Lambda Web Adapter
The web application returns a random quotation on each page refresh. The Quotations are by physicist Richard Feynmann.
The stack used include:
- AWS Lambda
- AWS DynamoDB
- Python Flask
- Docker
The terraform to create the infra is in terraform_files. Note that it currently creates the ECR repo but since we are also deploying the lambda as an image, it will error. Still trying to work round that issue...
terraform -chdir=terraform_files init
terraform -chdir=terraform_files plan -out=tfplan
terraform -chdir=terraform_files apply tfplan
To seed the database, the provided quotes.csv file has a sample 11 quotes:
python aws_dynamodb.py --csv quotes.csv
Note the ECR url as you will need to build and push the image to ECR manually.
To view the application, use the function url in the output e.g. https://XXXXX.lambda-url.eu-west-1.on.aws/
To run locally, it uses docker compose:
docker compose up
docker compose down
To run automatic rebuild:
docker compose watch
View the application by visiting http://localhost:7531