DVA-C02 Development with AWS Services Practice Question
A developer is deploying an application using AWS CloudFormation. The template includes an AWS::Lambda::Function resource. The developer wants to ensure that the Lambda function's code is automatically updated when the source code in S3 changes. Which approach should the developer use?
⚠ Common exam trap
Candidates often assume that simply uploading a new deployment package to the same S3 bucket and key will automatically trigger a Lambda update during a CloudFormation stack update. However, CloudFormation does not inspect the contents or hash of the S3 object; it only checks if the template properties themselves have changed. Therefore, you must either change the S3 key or use S3 object versioning and update the version in the 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
✓
Specify the S3 object version in the template and update the version number in the template when code changes.
AWS CloudFormation detects changes to the `AWS::Lambda::Function` resource's `Code` property only when the properties defined in the template (such as `S3Key` or `S3ObjectVersion`) change. If you upload a new deployment package to S3 using the same bucket and key, CloudFormation will not detect any change and will not update the Lambda function. To resolve this, you should enable S3 Versioning on the bucket, specify the `S3ObjectVersion` in the CloudFormation template, and update this version parameter in the template whenever the code is updated.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✓
Specify the S3 object version in the template and update the version number in the template when code changes.
Why this is correct
When a Lambda function's code is sourced from S3, CloudFormation monitors the S3ObjectVersion property within the Code block of the AWS::Lambda::Function resource. By explicitly including the S3 object's version ID in the template and updating this ID upon each code change, CloudFormation detects a modification to the resource's properties. This change then triggers an update to the Lambda function, ensuring the new code is deployed efficiently and reliably.
- ✗
Use the AWS::Lambda::Version resource to create a new version.
Why it's wrong here
The AWS::Lambda::Version resource is used to create an immutable snapshot of a Lambda function's *current* configuration and code, allowing for safe rollbacks and traffic shifting. However, it does not inherently update the underlying function's code itself. To deploy new code, the AWS::Lambda::Function resource's Code property must be modified, which AWS::Lambda::Version does not directly facilitate.
- ✗
Include the S3 bucket and key as template parameters and update the stack with a new key when code changes.
Why it's wrong here
While changing the S3Key property of the AWS::Lambda::Function resource *would* trigger an update, this approach requires creating a new S3 object with a unique key for every code change. This manual management of distinct S3 object keys is cumbersome and less efficient than leveraging S3's native object versioning capabilities, which automatically track changes to the same object key under a consistent key name.
- ✗
Use a custom resource backed by a Lambda function that polls S3 for changes.
Why it's wrong here
Implementing a custom CloudFormation resource to poll S3 for code changes introduces unnecessary complexity and operational overhead. CloudFormation already provides a direct and efficient mechanism for detecting Lambda code updates via the S3ObjectVersion property. This custom solution would also be less reactive, potentially introducing deployment delays, and is not idiomatic for this common use case.
Visual reference
Quick reference
AWS S3 Storage Class Comparison
| Storage Class | Min Duration | Retrieval | Use Case |
|---|---|---|---|
| S3 Standard | None | Immediate | Frequently accessed data |
| S3 Standard-IA | 30 days | Immediate | Infrequent access, rapid retrieval |
| S3 One Zone-IA | 30 days | Immediate | Non-critical infrequent data |
| S3 Intelligent-Tiering | None | Immediate–hours | Unknown or changing access patterns |
| S3 Glacier Instant | 90 days | Milliseconds | Archive with instant retrieval |
| S3 Glacier Flexible | 90 days | Minutes–hours | Archive, flexible retrieval |
| S3 Glacier Deep Archive | 180 days | Hours | Long-term compliance archive |
Go deeper
Related to this question
About these practice questions
One of 1,135 original DVA-C02 practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. 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.