2.1.1.3. Lambda Deployment and Versioning
First Principle: Lambda deployments enable agile updates, while versioning and aliases ensure controlled rollouts and safe testing of new application code in production.
Deploying and managing updates to your Lambda functions requires understanding how AWS handles versions and aliases to ensure smooth transitions and reliable operations.
Key Concepts of Lambda Deployment and Versioning:
- Deployment Package: Your Lambda function code and its dependencies are bundled into a
.zip
file or a container image for deployment. - $LATEST Version: This is the unpublished version of your function that you are actively working on. When you update your code, it automatically updates
$LATEST
. - Versions: When you publish a Lambda function version, it creates an immutable snapshot of your code and configuration. Each version has a unique ARN (Amazon Resource Name). This allows you to revert to previous versions if needed.
- Aliases: (Pointers to specific Lambda function versions.) Allow you to route traffic between two different versions of your function.
- Traffic Shifting: Aliases enable controlled rollouts (e.g., linear or canary deployments) by slowly shifting traffic from an old version to a new one. This is often managed via AWS CodeDeploy.
- Rollback: If a new version deployed via an alias has issues, you can quickly roll back traffic to the previous stable version.
Scenario: You've developed a new version of your Lambda function and want to deploy it to production. You need to test it with a small percentage of user traffic first before a full rollout, and have the ability to quickly revert if issues arise.
Reflection Question: How do Lambda versions and aliases enable controlled rollouts (e.g., linear or canary deployments via CodeDeploy) and simplify rollbacks, ensuring agile updates and safe testing of new application code in production?