DevOps
Cloud Infrastructure
Amazon Web Services
Lambda Deployment: Blue/Green vs. Canary

Lambda Deployment: Blue/Green vs. Canary

Managing the lifecycle of a serverless application requires more than just uploading code. You need to ensure updates are safe and rollbacks are instant. AWS Lambda enables this through Versions, Aliases, and Traffic Shifting.


🧩 The Building Blocks: Versions & Aliases

To understand Lambda deployment strategies, you must first master these two concepts:

  • Versions: An immutable snapshot of your code and configuration. Once a version is published (e.g., Version 1), it can never be changed.
  • Aliases: A mutable "pointer" that points to a specific version. You can point an alias called prod to Version 1 today, and Version 2 tomorrow.

🏗️ Deployment Architectures


🚀 1. Blue/Green Deployment (Instant)

In an instant Blue/Green deployment, you switch 100% of the traffic from the old version to the new version at once by updating the alias.

  • How it works: Point the prod alias from Version 1 directly to Version 2.
  • Pros: Simple, zero downtime.
  • Cons: High risk if the new version has a critical bug, as all users hit it immediately.
  • Rollback: Repoint the alias back to Version 1 instantly.

🐦 2. Canary Deployment (Gradual)

In a canary deployment, you shift a small percentage of traffic (e.g., 10%) to the new version. You monitor for errors, and if everything looks good, you gradually increase the traffic to 100%.

  • How it works: Configure the prod alias with Weighted Aliases.
  • Pros: Lowest risk. Only a small subset of users is affected by potential bugs.
  • Cons: Requires monitoring and longer deployment time.
  • Rollback: Reset the weight to 100% on Version 1.

📊 Technical Comparison

FeatureBlue/GreenCanary
Traffic ShiftInstant (0% to 100%)Gradual (e.g., 10% increments)
Rollback SpeedInstantInstant
Risk LevelModerateLowest
Best ForInternal tools, low-traffic APIsMission-critical, high-traffic apps
AWS AutomationAWS CodeDeployAWS CodeDeploy

🛠️ Automating with CodeDeploy

While you can shift traffic manually in the console, AWS CodeDeploy is typically used to automate these patterns in a CI/CD pipeline. Common CodeDeploy configurations include:

  • LambdaCanary10Percent5Minutes: Shifts 10% of traffic, waits 5 minutes, then shifts the rest.
  • LambdaLinear10PercentEvery1Minute: Shifts 10% every minute until 100% is reached.

[!TIP] Use CloudWatch Alarms When using Canary deployments with CodeDeploy, you can configure Rollback Alarms. If your new Lambda version starts throwing errors or high latency, CodeDeploy will detect the CloudWatch alarm and automatically roll back the traffic to the stable version.