Courseiva
Question 886 of 724
DeploymenthardMultiple ChoiceObjective-mapped

How to enable canary deployments for API Gateway in AWS SAM?

A developer is deploying a serverless application using AWS SAM. The application consists of multiple Lambda functions and an Amazon API Gateway. The developer wants to enable canary deployments for the API Gateway stage to gradually shift traffic. Which SAM resource attribute should the developer use?

Quick Answer

The answer is the `DeploymentPreference` attribute on the `AWS::Serverless::Api` resource. This attribute is correct because it directly integrates AWS SAM with AWS CodeDeploy to manage canary deployments for API Gateway, allowing you to gradually shift traffic to a new stage version using patterns like `Canary10Percent5Minutes`. It also supports automatic rollbacks via CloudWatch Alarms, making it a fully managed solution for safe, incremental releases. On the AWS Certified Developer Associate DVA-C02 exam, this tests your understanding of how SAM abstracts CodeDeploy’s deployment configuration into a simple YAML attribute—a common trap is confusing it with `AutoPublishAlias` (used for Lambda functions) or assuming you must manually create a CodeDeploy application. Remember the memory tip: “SAM’s DeploymentPreference is the canary in the API coal mine”—if you see gradual traffic shifting for API Gateway in a SAM template, that attribute is your answer.

⚠ Common exam trap

Many candidates confuse `CanarySetting` (a direct CloudFormation property for API Gateway stages) with the SAM-specific `DeploymentPreference` attribute, which is the correct abstraction for canary deployments in SAM templates.

Answer choices

Why each option matters

Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.

Correct answer & explanation

DeploymentPreference

The `DeploymentPreference` attribute in AWS SAM's `AWS::Serverless::Api` resource enables canary deployments for API Gateway stages. This attribute allows you to configure traffic shifting patterns, such as linear or canary, by specifying settings like `Type` (e.g., `Canary10Percent5Minutes`) and `Alarms` to automatically roll back on failures. It directly integrates with AWS CodeDeploy to manage the gradual traffic shift without manual intervention.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • DeploymentPreference

    Why this is correct

    The DeploymentPreference attribute in SAM is used to define traffic shifting and canary deployment settings for Lambda and API Gateway.

  • CanarySetting

    Why it's wrong here

    CanarySetting is a sub-property of DeploymentPreference, not a top-level attribute in SAM. It specifies the canary configuration within deployment preferences.

  • StageName

    Why it's wrong here

    StageName is used to name the API Gateway stage, not to configure deployment strategies.

  • MethodSettings

    Why it's wrong here

    MethodSettings is used to configure API Gateway settings like caching and throttling for individual methods, not traffic shifting.

Quick reference

Cloud Service Model Comparison

ModelYou ManageProvider ManagesExamples
IaaSOS, runtime, apps, dataHardware, hypervisor, networkingEC2, Azure VMs, GCP Compute Engine
PaaSApps and dataOS, runtime, middleware, hardwareElastic Beanstalk, Azure App Service
SaaSData and settings onlyEverything elseMicrosoft 365, Salesforce, Workday
FaaS / ServerlessFunction code onlyInfra, scaling, runtimeLambda, Azure Functions, Cloud Run
CaaSContainers and appsKubernetes, OS, hardwareEKS, AKS, GKE

About these practice questions

Courseiva creates original exam-style practice questions with explanations and wrong-answer analysis. It does not publish real exam questions, exam dumps, or protected exam content. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

Same concept, more angles

3 more ways this is tested on DVA-C02

These questions test the same concept from different angles. Work through them to make sure you can recognise it however the exam phrases it.

Variation 1. A company deploys a serverless application using AWS SAM. The application includes an API Gateway REST API and multiple Lambda functions. The developer wants to deploy a new version of the API with a canary release strategy, sending 10% of traffic to the new version initially. Which SAM template configuration should the developer use?

medium
  • A.Set Type: Canary in the DeploymentPreference of the Lambda function and add CanarySetting: { Percent: 10 } under DeploymentPreference.
  • B.Set CanarySetting: { Percent: 10 } in the API Gateway resource's properties.
  • C.Set Type: Canary and TrafficShiftType: Canary in the DeploymentPreference of the Lambda function.
  • D.Set Type: Canary in the DeploymentPreference of the Lambda function and add a Percentage: 10 property.

Why A: To implement a canary release strategy for a Lambda function using AWS SAM, you must configure the `DeploymentPreference` property under the `AWS::Serverless::Function` resource. AWS SAM integrates with AWS CodeDeploy to manage the traffic shifting. You must specify a predefined CodeDeploy configuration for the `Type` property, such as `Canary10Percent5Minutes` (which routes 10% of traffic to the new version for 5 minutes before shifting 100% of traffic). Additionally, you must specify the `AutoPublishAlias` property on the Lambda function, which tells SAM to create an alias and detect new deployments to trigger the CodeDeploy traffic shifting. Custom percentages like `Percent: 10` or `Type: Canary` are not valid configurations for Lambda deployment preferences in SAM.

Variation 2. A developer is deploying a serverless application using AWS SAM. The application consists of an API Gateway endpoint that triggers an AWS Lambda function. The developer wants to enable canary deployments to gradually shift traffic to a new Lambda version. Which SAM resource attribute should the developer configure?

medium
  • A.ReservedConcurrentExecutions
  • B.Timeout
  • C.AutoPublishAlias and DeploymentPreference
  • D.ProvisionedConcurrency

Why C: `AutoPublishAlias` automatically creates and updates a Lambda alias (e.g., `live`) that points to the latest version of your function, while `DeploymentPreference` enables canary, linear, or all-at-once traffic shifting between the old and new alias versions. Together, they allow gradual traffic migration to a new Lambda version without manual alias management.

Variation 3. A developer is deploying a serverless application using AWS SAM. The application consists of an API Gateway REST API and multiple AWS Lambda functions. The developer wants to deploy the application to a production environment with minimal downtime. Which deployment strategy should the developer use?

easy
  • A.Create a blue/green deployment using AWS Elastic Beanstalk.
  • B.Delete the existing stack and deploy a new one.
  • C.Perform a rolling update by updating functions one by one.
  • D.Use SAM's built-in canary deployment with traffic shifting.

Why D: AWS SAM supports canary deployments with traffic shifting, allowing gradual rollout of new versions and minimizing downtime. Option A is wrong because AWS Elastic Beanstalk is not part of SAM; SAM uses AWS CodeDeploy for canary deployments, not Elastic Beanstalk. Option B is wrong because deleting and redeploying the entire stack causes downtime. Option C is wrong because rolling updates by updating functions one by one is not a built-in SAM feature; SAM leverages traffic shifting via AWS CodeDeploy.

Last reviewed: Jun 11, 2026

Question Discussion

Share a tip, memory trick, or ask about the reasoning behind this question. Do not post real exam questions, leaked content, braindumps, or copyrighted exam material. Comments are moderated and may be removed without notice.

Loading comments…

Sign in to join the discussion.

This DVA-C02 practice question is part of Courseiva's free Amazon Web Services certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the DVA-C02 exam.