Hedronite · Cert Lesson · AWS DOP-C02 · Tue 2026-10-13 · BACKFILL

AWS DOP-C02 Lambda aliases and CodeDeploy canary and linear traffic shifting

Callers hit the alias, CodeDeploy moves the weight, alarms decide.

Lesson Class: Cert (T2 · SDLC automation)
Referent: Lambda aliases · CodeDeploy Lambda configs · SAM
Not a repeat: not 08-05 EC2/ECS blue/green · 09-25 StackSets
Paired Ops: Nickel deploy config
Version Is Frozen, Alias Moves
Never invoke $LATEST.
Read the Config Name
Canary is two steps; linear is equal steps.
Two Hooks, Two Alarm Paths
Hooks gate; alarms roll back.
Ten percent saw it; ninety percent never did.

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:

NameShape
CodeDeployDefault.LambdaCanary10Percent5Minutes10 percent, wait 5 minutes, then 100 percent
CodeDeployDefault.LambdaLinear10PercentEvery1Minuteadd 10 percent each minute until 100
CodeDeployDefault.LambdaAllAtOnceeverything 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

  1. Version 8 is published; PreTraffic runs against it and reports Succeeded.
  2. live routes 10 percent to 8, 90 percent to 7.
  3. Five minutes in, Orders5xxAlarm goes to ALARM.
  4. CodeDeploy stops the deployment and, with automatic rollback on alarm enabled, routes 100 percent back to 7. PostTraffic never runs.

If PreTraffic reports Failed instead, no traffic shifts at all.

§V. Drills

  1. API Gateway invokes orders-api:$LATEST. Why does the canary not protect users? (Traffic bypasses the alias.)
  2. You need 10 percent for 30 minutes, then everything. Canary or linear? (Canary: LambdaCanary10Percent30Minutes.)
  3. A hook function runs but the deployment hangs until timeout. What did it forget? (PutLifecycleEventHookExecutionStatus.)
  4. 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