Course contentsShow
← Cloud and Infrastructure
Lesson 1837 of 2,98938. AWS Native CI/CDFree lesson

CodeDeploy for Lambda and ECS

Deploy Lambda function versions with traffic shifting and ECS services with blue/green deployment strategies.

CodeDeploy for Lambda and ECS

What you'll learn: How to safely deploy Lambda functions with gradual traffic shifting and ECS services using blue/green deployments through CodeDeploy.

The Core Concept

While CodeDeploy started with EC2 deployments, it also supports serverless Lambda functions and containerized ECS services—each with specialized deployment patterns that minimize risk during updates.

For Lambda, CodeDeploy manages version-based traffic shifting. Instead of instantly routing all invocations to a new function version, you can gradually shift traffic (e.g., 10% for 5 minutes, then 100%) while monitoring for errors. If CloudWatch alarms detect issues, CodeDeploy automatically rolls back to the previous version. Think of it like slowly opening a valve—you can detect pressure problems before fully committing.

For ECS, CodeDeploy orchestrates blue/green deployments at the service level. It provisions a completely new task set (green) running your updated container image alongside the existing one (blue). Traffic shifts from the old Application Load Balancer target group to the new one based on your deployment configuration. After successful validation, the blue environment is terminated.

Key Differences

Lambda deployments use:

  • Canary (two increments: X% then 100%)
  • Linear (traffic increases in equal steps)
  • AllAtOnce (immediate switch)

ECS deployments require:

  • An ALB with two target groups
  • ECS service configured for CODE_DEPLOY deployment controller
  • AppSpec file defining task definitions and load balancer configuration

Both leverage deployment configurations to control rollout speed and automatic rollback triggers based on CloudWatch metrics.

Key Takeaway: CodeDeploy extends beyond EC2 to safely deploy Lambda functions using gradual traffic shifting and ECS services using blue/green deployments, both with automatic rollback capabilities when issues are detected.