This project will automate the deployment of AWS Lambda Layers for Python-based deployments using AWS CloudFormation. Traditional Lambda Layer management often leads to outdated dependencies, as layers are typically created manually and updated infrequently. This project is ideal for AWS developers and DevOps engineers who want to streamline their Lambda function management and ensure consistent Python package versions across their serverless applications.
- Serverless Applications: Keep dependencies current across multiple Lambda functions
- CI/CD Pipelines: Automate Lambda Layer updates as part of your deployment process
- Development Teams: Standardize package versions across different environments
- Security Compliance: Ensure your functions use the latest, most secure package versions
Deployment Flow
- Customers deploy the AWS CloudFormation template lambda-layer-deployment-template-python.yaml with parameters:
- Python package name (See Supported Packages (Python))
- Lambda runtime version (See Supported Runtimes - AWS Lambda (Python))
- Lambda CPU architecture (See Supported Architectures - AWS Lambda)
- The AWS Lambda - Layer Creator function will:
- Download the specified package from PyPI to ephemeral storage
- Packages all dependencies into a Lambda Layer ZIP File
- Uploads the Lambda Layer ZIP file to Amazon S3 bucket
- AWS CloudFormation Template creates Lambda Layer from ZIP stored in Amazon S3 using:
- The specified Lambda runtime version
- Selected Lambda CPU architecture
- Latest package version
- The AWS Lambda - Layer Tester validates:
- Package installation
- Import functionality
- Runtime compatibility
Important Notes
- All packages will be deployed using the latest package version from PyPI
- This project has logic in place to support:
- Simple packages names (e.g.,
boto3
) - Hyphenated packages with Python import conversion (e.g.,
aws-lambda-powertools
βaws_lambda_powertools
)
- Simple packages names (e.g.,
- This list of supported packages represents commonly used packages that have been tested by the developer, and can be extended based on your needs with your own testing.
- python3.10
- python3.11
- python3.12
- python3.13
- arm64
- x86_64
- AWS Console access with appropriate permissions
- Python 3.10 or later
- AWS account with Lambda and S3 access
-
Download the AWS CloudFormation Template: lambda-layer-deployment-template-python.yaml
-
Launch AWS CloudFormation
- Open AWS CloudFormation Console
- Click "Create stack" β "With new resources (standard)"
- Choose "Upload a template file"
- Upload
lambda-layer-deployment-template-python.yaml
- Click "Next"
-
Configure Stack
- Stack name: Provide a unique stack name (e.g.,
lambda-layer-stack
) - Parameters:
- PackageName: Choose from supported packages (e.g.,
boto3
) - Runtime: Select Python version (e.g.,
python3.13
) - Architecture: Choose
arm64
orx86_64
- PackageName: Choose from supported packages (e.g.,
- Click "Next"
- Stack name: Provide a unique stack name (e.g.,
-
Review and Create
- Review configuration
- Acknowledge IAM resource creation
- Click "Create stack"
-
Monitor Deployment
- Wait for stack creation (approximately 2-3 minutes)
- Check the "Events" tab for progress
- Stack status should show "CREATE_COMPLETE"
- Review the "Outputs" tab to validate deployment
Your Lambda Layer is now ready for use with your AWS Lambda functions. For detailed instructions on adding layers to Lambda functions, refer to the AWS Lambda Developer Guide - Using Layers.
- AWS Lambda Developer Guide - Managing Lambda dependencies with layers
- AWS Lambda Developer Guide - Selecting and configuring an instruction set architecture for your Lambda function
- AWS Lambda Developer Guide - Lambda Runtimes
- AWS Lambda Developer Guide - Using AWS CloudFormation with layers
- PEP 423 β Naming conventions and recipes related to packaging
- Layer Creation Failures
- Check CloudWatch logs for the
LayerCreatorFunction
- Verify PyPI package name is correct
- Ensure S3 bucket permissions are properly configured
- Check CloudWatch logs for the
- Layer Testing Failures
- Examine
LayerTestCustomResource
logs in CloudWatch - Verify Python runtime compatibility
- Check if package import name matches PyPI name
- Examine
- Deployment Issues
- Ensure AWS CLI has sufficient permissions
- Verify CloudFormation service role permissions
- Check if the specified runtime/architecture combination is supported
See CONTRIBUTING for more information
See CONTRIBUTING - Security issue notifications for more information.
This library is licensed under the MIT-0 License. See the LICENSE file.
Taylan Unal, Specialist Solutions Architect II, Amazon Web Services