This project demonstrates how a simple Flask API can be deployed to AWS Lambda using the Serverless Framework.
Lambda function needs to have API_KEY variable set up. To do this, we utilize AWS Systems Manager Parameter Store. The variable can be set with:
aws ssm put-parameter --name "/flask-serverless-lambda/api-key" --value "your-api-key-value" --type SecureString
The value does not matter.
- Copy the example environment file:
cp env.example .env
- Edit
.env
and add your environment variables. - Load the variables into your shell:
source .env
- Build the Docker image:
docker compose build
- Start the container:
docker compose up -d
- The API will be available at:
http://127.0.0.1:${PORT}/home
To enter the container shell:
docker compose exec app bash
To deploy the API using Serverless Framework, run:
serverless deploy
For GitHub Actions and manual deployments to work correctly, ensure that all necessary environment variables are set as GitHub Action Secrets.
- Flask – Web framework for Python
- Docker – Containerization for local development
- Serverless Framework – Deployment automation for AWS Lambda
- AWS Lambda – Serverless compute service
This project is licensed under the MIT License.
- If you need to update environment variables, update
.env
and restart the container with:docker compose up -d --build
- For debugging deployment issues, check logs with:
serverless logs -f function_name