This directory contains examples for deploying AWS Lambda functions using PipeCD with direct source code deployment instead of container images, making it much easier to get started.
Previously, the Lambda tutorial required:
- ❌ Building and pushing container images to ECR
- ❌ Complex Docker setup
- ❌ ECR repository management
Now it uses:
- ✅ Simple Python source code
- ✅ Automatic packaging by PipeCD
- ✅ No manual zip building or S3 uploads
- ✅ Minimal prerequisites (just an IAM role)
lambda/
├── simple/ # Simple deployment example
│ ├── src/
│ │ ├── index.py # Lambda function source code
│ │ └── requirements.txt # Python dependencies
│ ├── function.yaml # Lambda function configuration
│ └── app.pipecd.yaml # PipeCD application config
├── canary/ # Canary deployment example
│ ├── src/
│ │ ├── index.py # Enhanced Lambda function
│ │ └── requirements.txt # Python dependencies
│ ├── function.yaml # Lambda function configuration
│ └── app.pipecd.yaml # PipeCD canary pipeline config
└── README.md # This file
- AWS CLI configured with appropriate permissions
- IAM role for Lambda execution
Edit simple/function.yaml:
spec:
name: PipeCDTutorial_Simple
role: arn:aws:iam::123456789012:role/lambda-execution-role
source:
git: "" # Empty means same repository
ref: "" # Empty means current commit
path: "src" # Path to source code directory
runtime: python3.9
handler: index.lambda_handlerFollow the main tutorial instructions to register and deploy the application.
That's it! PipeCD will automatically:
- Package your source code into a zip file
- Deploy it to AWS Lambda
- Handle all the complexity for you
- Returns a JSON response with greeting and metadata
- Includes request information and timestamps
- Uses only Python standard library (no dependencies)
- Perfect for testing basic Lambda deployment
- Enhanced version with deployment tracking
- Additional logging for canary deployment monitoring
- Environment variables for version control
- Demonstrates gradual rollout capabilities
-
Edit
src/requirements.txt:requests==2.31.0 boto3==1.34.0 -
Commit and push - PipeCD will automatically install dependencies during packaging
- Edit
src/index.pywith your custom logic - Test locally:
python src/index.py - Commit and push - PipeCD handles the rest
Add environment variables in function.yaml:
spec:
environment:
CUSTOM_VAR: "custom_value"
API_ENDPOINT: "https://api.example.com"Test your function locally before deployment:
cd simple/src/
python index.pyThis runs the function with a test event and displays the output.
- Uses
simple/directory - Quick sync strategy
- Immediate deployment
- Uses
canary/directory - Gradual traffic shifting (10% → 50% → 100%)
- Built-in rollback capabilities
- Wait stages for monitoring
- Verify IAM role has Lambda execution permissions
- Check function.yaml syntax
- Ensure source code is in the correct directory structure
- Review CloudWatch logs
- Test function locally first
- Verify environment variables
- Try the simple deployment first
- Experiment with the canary deployment
- Customize the function for your use case
- Explore PipeCD's advanced Lambda features
For more information, see the PipeCD Lambda documentation.