DVA-C02 Development with AWS Services Practice Question
A developer is using the AWS Serverless Application Model (SAM) to define a serverless application with an API Gateway endpoint. The developer wants to enable API caching only in the development stage to speed up testing, but disable it in the production stage to ensure data freshness. What is the most efficient way to achieve this with SAM?
⚠ Common exam trap
It's easy for candidates to think caching must be managed via usage plans or custom resources, overlooking SAM's ability to conditionally set API Gateway stage properties directly through parameters and conditions in a single template.
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
✓
Use AWS SAM parameters with a condition to set CacheClusterEnabled based on the stage parameter.
AWS SAM parameters allow you to define a stage parameter (e.g., 'dev' or 'prod') and use a condition to conditionally set the `CacheClusterEnabled` property on the `AWS::Serverless::Api` resource. This is the most efficient approach because it uses a single template and SAM's built-in intrinsic functions (like `Fn::Equals`) to toggle caching based on the deployment stage, avoiding separate templates or post-deployment custom resources.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✓
Use AWS SAM parameters with a condition to set CacheClusterEnabled based on the stage parameter.
Why this is correct
AWS SAM parameters, combined with CloudFormation conditions, provide a robust mechanism to tailor resource configurations based on deployment-time inputs, such as a 'stage' parameter. By defining a condition that evaluates the 'stage' parameter (e.g., `Fn::Equals` 'prod'), the `CacheClusterEnabled` property can be conditionally set to `true` or `false` using `Fn::If`. This approach allows a single, consistent SAM template to manage multiple environments (e.g., dev, prod) without requiring manual modifications or separate template files, adhering to Infrastructure as Code best practices.
- ✗
Deploy two separate SAM templates, one for each stage.
Why it's wrong here
Deploying two separate SAM templates, one for each stage, introduces significant operational overhead and increases the risk of configuration drift. Maintaining distinct templates means that any update or bug fix to the core application logic or infrastructure must be meticulously replicated across both files, leading to duplicated effort and potential inconsistencies. This approach undermines the efficiency and reliability benefits of Infrastructure as Code, making deployments and maintenance more error-prone and time-consuming.
- ✗
Use a custom resource to toggle caching after deployment.
Why it's wrong here
Using a custom resource to toggle caching after deployment introduces an out-of-band configuration step that is not managed within the SAM template, violating the infrastructure-as-code principle and creating drift between the template definition and the deployed state. This approach is tempting because custom resources are designed to invoke AWS Lambda functions for provisioning logic that AWS CloudFormation does not natively support, such as integrating with third-party APIs or performing complex post-deployment validations.
- ✗
Enable caching globally and configure a usage plan with a quota for production.
Why it's wrong here
Enabling caching globally and configuring a usage plan with a quota for production is an incorrect approach because API Gateway usage plans serve a fundamentally different purpose than controlling caching behavior. Usage plans are designed to manage client access to APIs, enforce throttling limits (requests per second), and set data quotas for API keys, thereby governing how much and how often specific consumers can interact with the API. They do not, however, provide any mechanism to enable, disable, or configure the API Gateway's caching cluster, which is a distinct performance optimization setting.
Quick reference
Cloud Service Model Comparison
| Model | You Manage | Provider Manages | Examples |
|---|---|---|---|
| IaaS | OS, runtime, apps, data | Hardware, hypervisor, networking | EC2, Azure VMs, GCP Compute Engine |
| PaaS | Apps and data | OS, runtime, middleware, hardware | Elastic Beanstalk, Azure App Service |
| SaaS | Data and settings only | Everything else | Microsoft 365, Salesforce, Workday |
| FaaS / Serverless | Function code only | Infra, scaling, runtime | Lambda, Azure Functions, Cloud Run |
| CaaS | Containers and apps | Kubernetes, OS, hardware | EKS, AKS, GKE |
Go deeper
Related to this question
About these practice questions
This DVA-C02 question is part of Courseiva's 724-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam dumps. Learn why practice questions differ from exam dumps →
JA
Written by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
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.