cheeyeo / aws_lambda_web_application

Example of running python Flask web app in AWS Lambda with terraform IAC

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

AWS LAMBDA Web App

image

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.

Deployment

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/

Development

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

References

About

Example of running python Flask web app in AWS Lambda with terraform IAC


Languages

Language:HCL 38.9%Language:Python 32.6%Language:CSS 16.3%Language:HTML 7.2%Language:Dockerfile 5.1%