AWS DOP-C02 Lambda aliases and CodeDeploy canary and linear traffic shifting
Callers hit the alias, CodeDeploy moves the weight, alarms decide.
Callers point at an alias, the alias points at versions, and CodeDeploy moves the weight. Alarms decide whether it keeps moving.
§I. Frame
The 08-05 DOP lesson covered CodeDeploy blue/green on EC2 and ECS. On Lambda there are no instances to swap. A deploy moves traffic between two immutable function versions behind one alias, in steps, and rolls back if an alarm fires. Exam questions test the names of the deployment configurations, the two hooks, and where alarms plug in.
Scenario: orders-api runs behind alias live. Ship version 8 to 10 percent of traffic, wait 10 minutes, then send the rest, and roll back on 5xx or p99 latency alarms. The paired Ops lesson types exactly these settings in Nickel.
§II. Three techniques
Version Is Frozen, Alias Moves (named technique). Publishing creates a numbered, immutable version. An alias is a named pointer to one version, or to two versions with a weight on the second (routing config). Event sources, API Gateway, and callers should invoke the alias ARN, never $LATEST, or traffic shifting has nothing to shift.
Read the Config Name (named technique). CodeDeploy Lambda configurations encode the shape in the name:
| Name | Shape |
|---|---|
CodeDeployDefault.LambdaCanary10Percent5Minutes | 10 percent, wait 5 minutes, then 100 percent |
CodeDeployDefault.LambdaLinear10PercentEvery1Minute | add 10 percent each minute until 100 |
CodeDeployDefault.LambdaAllAtOnce | everything at once |
Canary is two steps. Linear is equal steps. The docs list more intervals (canary 5/10/15/30 minutes, linear every 1/2/3/10 minutes), and you can define custom ones. The bootcamp notes pin the two most quoted: LambdaLinear10PercentEvery10Minutes and LambdaCanary10Percent10Minutes.
Two Hooks, Two Alarm Paths (named technique). A Lambda AppSpec has two hooks: BeforeAllowTraffic and AfterAllowTraffic. Each names a Lambda function that runs a check and must report back with PutLifecycleEventHookExecutionStatus (Succeeded or Failed). Separately, CloudWatch alarms attached to the deployment group stop the deployment and, with automatic rollback enabled, shift the alias back.
§III. AppSpec and SAM
AppSpec for the Lambda compute platform (from the docs' structure, not validated against an account):
version: 0.0
Resources:
- OrdersApi:
Type: AWS::Lambda::Function
Properties:
Name: orders-api
Alias: live
CurrentVersion: "7"
TargetVersion: "8"
Hooks:
- BeforeAllowTraffic: orders-api-pretraffic
- AfterAllowTraffic: orders-api-posttraffic
Most teams do not write that file. SAM generates it from DeploymentPreference:
OrdersApi:
Type: AWS::Serverless::Function
Properties:
Handler: bootstrap
Runtime: provided.al2023
AutoPublishAlias: live
DeploymentPreference:
Type: Canary10Percent10Minutes
Alarms:
- !Ref Orders5xxAlarm
- !Ref OrdersP99Alarm
Hooks:
PreTraffic: !Ref PreTrafficHook
PostTraffic: !Ref PostTrafficHook
AutoPublishAlias publishes a new version when the code changes and points live at it through CodeDeploy. SAM creates the CodeDeploy application and deployment group.
§IV. What happens on a bad deploy
- Version 8 is published;
PreTrafficruns against it and reports Succeeded. liveroutes 10 percent to 8, 90 percent to 7.- Five minutes in,
Orders5xxAlarmgoes to ALARM. - CodeDeploy stops the deployment and, with automatic rollback on alarm enabled, routes 100 percent back to 7.
PostTrafficnever runs.
If PreTraffic reports Failed instead, no traffic shifts at all.
§V. Drills
- API Gateway invokes
orders-api:$LATEST. Why does the canary not protect users? (Traffic bypasses the alias.) - You need 10 percent for 30 minutes, then everything. Canary or linear? (Canary:
LambdaCanary10Percent30Minutes.) - A hook function runs but the deployment hangs until timeout. What did it forget? (
PutLifecycleEventHookExecutionStatus.) - Which SAM property creates a new version and drives the alias? (
AutoPublishAlias.)
Close
Version Is Frozen Alias Moves, Read the Config Name, Two Hooks Two Alarm Paths. Invoke the alias, pick the shape by name, gate with hooks, and let alarms roll it back.
Related
- Tome: DOP notes part 2, CodeDeploy section (grounded-in)
- Web: CodeDeploy deployment configurations · AppSpec hooks · Lambda aliases · SAM gradual deploys · DOP-C02 exam page
- Paired Ops: Nickel deploy config (2026-10-13) · Prior DOP: CodePipeline and blue/green 08-05