This project demonstrates how to create, deploy, and test AWS Lambda functions using different deployment methods:
- Plain Lambda Function: A simple Lambda function with external dependencies packaged in a zip file
- Docker Image Lambda Function: A Lambda function packaged as a Docker container
- Lambda Function with Layers: A Lambda function that uses Lambda layers for dependencies and demonstrates proper package importing
finally-learn-lambda/
├── README.md # This file
├── cdk-app/ # AWS CDK application for deployment
│ ├── app.py # CDK application entry point
│ ├── cdk_stack.py # CDK stack definition
│ └── requirements.txt # CDK dependencies
├── lambda-functions/ # Lambda function implementations
│ ├── plain-lambda/ # Simple Lambda implementation
│ │ ├── lambda_function.py # Function code
│ │ └── requirements.txt # Dependencies
│ ├── docker-lambda/ # Docker-based Lambda
│ │ ├── Dockerfile # Docker configuration
│ │ ├── lambda_function.py # Function code
│ │ └── requirements.txt # Dependencies
│ └── layer-lambda/ # Lambda with layers
│ ├── src/ # Lambda function code
│ │ ├── lambda_function.py # Main function
│ │ └── utils/ # Local imports example
│ │ └── helper.py # Helper module
│ └── layers/ # Lambda layers
│ └── dependencies/ # Dependencies layer
└── template.yaml # AWS SAM template for local testing
- AWS CLI installed and configured
- AWS CDK CLI installed (
npm install -g aws-cdk) - Python 3.8+ installed
- Docker installed (for Docker-based Lambda and SAM local testing)
- AWS SAM CLI installed
- Set up a virtual environment:
python -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate- Install CDK dependencies:
cd cdk-app
pip install -r requirements.txt- Bootstrap CDK (if you haven't already):
cdk bootstrapTo deploy all Lambda functions:
cd cdk-app
cdk deployTo test the Lambda functions locally:
sam local invoke PlainLambdaFunction -e events/event.json
sam local invoke DockerLambdaFunction -e events/event.json
sam local invoke LayerLambdaFunction -e events/event.jsonSee the detailed sections below for explanations on each Lambda function type.