Course menuDOP-C02

Exams / DOP-C02 / Study guide / Lambda deployments (aliases, traffic shifting, SAM)

Lambda deployments (aliases, traffic shifting, SAM): DOP-C02 study notes and practice questions

What to know about Lambda deployments (aliases, traffic shifting, SAM) for the DOP-C02 exam, from the SDLC Automation domain (22% of the exam guide), then 2 free questions to test it. Part of the DOP-C02 study guide.

Last verified against current AWS documentation ·How we write our questions

What to know for the exam

Serverless deployment questions ask how to release a function gradually and roll back automatically.

Versions and aliases

  • A version is an immutable snapshot of code and configuration with its own ARN.
  • An alias (such as live) points to a version and can split traffic between two versions by weight.
  • Callers use the alias ARN, so promotion is just moving the alias.

Traffic shifting with CodeDeploy

Configuration Behavior
Canary10Percent5Minutes (and others) 10% for 5 minutes, then 100%
Linear10PercentEvery1Minute (and others) 10% more each minute
AllAtOnce Immediate
  • Hooks: BeforeAllowTraffic and AfterAllowTraffic Lambda functions run tests and report success or failure.
  • CloudWatch alarms on errors or latency trigger automatic rollback to the old version.

SAM makes it declarative

AutoPublishAlias: live
DeploymentPreference:
  Type: Canary10Percent5Minutes
  Alarms: [ !Ref ErrorsAlarm ]
  Hooks: { PreTraffic: !Ref PreTrafficFn }

Layers and sharing

  • Layer versions are immutable, each with its own ARN; share with an account or a whole organization through layer permissions.
  • Functions must be updated to use a new layer version.

API Gateway

  • Stages with canary release settings send a percentage of traffic to a new deployment.
  • Stage variables can point at Lambda aliases.

Other points

  • Provisioned concurrency on the alias avoids cold starts during shifts.
  • Lambda container images deploy from ECR.
  • Reserved concurrency protects downstream systems.

Common traps

  • Updating $LATEST in production with no alias.
  • Writing a script to shift weights when SAM and CodeDeploy do it.
  • Expecting a new layer version to update functions automatically.
  • Alarms on the whole function rather than the new version, which can hide errors during a small canary.

Try the 2 practice questions

An insurance firm runs its claims-intake API as a set of AWS Lambda functions defined with AWS SAM. Claims adjusters use the API during business hours, and the team releases updates several times a week.

The team wants a new version of the claim-validation function to receive 10 percent of invocations at first. The remaining traffic should move after 5 minutes if the function's error alarm stays in OK, and if the alarm fires during the shift, traffic must return to the previous version automatically.

Developers want this configured in the same template as the function, with no separate deployment pipeline to maintain.

Which change meets these requirements with the LEAST operational overhead?

Choose one answer.

  1. A. Set AutoPublishAlias and a DeploymentPreference of Canary10Percent5Minutes in the SAM template, and list the error alarm so that CodeDeploy rolls back when it fires.
  2. B. Create a Lambda alias that sends 10 percent of invocations to the new version through weighted routing, and write a Step Functions state machine that raises the weight after 5 minutes.
  3. C. Deploy each new version as a separate Lambda function behind its own API Gateway stage, and change the custom domain mapping to the new function after the test team signs off.
  4. D. Keep the function at $LATEST and set reserved concurrency to 10 on the new version, so that only a tenth of the requests can reach the new code while the old code handles the rest.
Show the answer and explanation

Answer: A

Explanation

SAM deployment preferences use CodeDeploy to move a Lambda alias between versions in stages and roll back when a listed CloudWatch alarm fires. Declaring it in the template keeps the canary, the wait and the alarm together with the function, and the team writes no extra orchestration. Weighted aliases need custom code, cutovers are all or nothing, and concurrency settings do not choose code versions.

A canary deployment with alarm-based rollback Users reach the service through a traffic-shifting layer such as a Lambda alias, load balancer or endpoint. Most traffic goes to the current version and a small share goes to the new version. A CloudWatch alarm on the new version's errors rolls traffic back to the current version. Users Traffic shifting alias, ALB or endpoint Current version most traffic New version small share first CloudWatch alarm errors, latency roll back
Canary10Percent5Minutes sends a tenth of the traffic to the new version first, and the error alarm triggers rollback.

Study

A SaaS startup publishes a shared logging layer for AWS Lambda. The layer is used by 30 functions owned by teams in 12 accounts within one AWS Organization, and each function references a specific version of the layer by its ARN.

Layer versions cannot be changed after they are published. When the logging code needs a fix, every consuming team must be able to move its functions to the new version during its own deployment.

The layer must not be public, and no team may copy the logging code into its own function package.

Which approach meets these requirements?

Choose one answer.

  1. A. Overwrite the current layer version with the fixed code, so that every function picks up the change on its next cold start without any deployment.
  2. B. Publish a new layer version, grant the organization's ID permission to use it, and have each team move to the new version ARN in its own deployment.
  3. C. Make the layer public, so that every account can use it, and have each function reference the latest layer version ARN so that updates arrive automatically.
  4. D. Copy the logging code into each function's deployment package, remove the layer, and let each team control its own releases, since the layer is no longer shared.
Show the answer and explanation

Answer: B

Explanation

Lambda layer versions are immutable, and each one has its own ARN. A layer version permission can grant use to every account in an organization without making the layer public, and each team then points its functions at the new version during its own deployment. Overwriting versions, making the layer public or copying the code each miss a stated requirement.

Study

Want more on Lambda deployments (aliases, traffic shifting, SAM)? The 5 full-length practice sets have 7 more Lambda deployments (aliases, traffic shifting, SAM) questions, 375 in all, none of them in the free exam. One payment of $14.99, no subscription. See the practice sets

Study Lambda deployments (aliases, traffic shifting, SAM)

More SDLC Automation topics