How to Update Lambda Code in CloudFormation When the S3 Zip Changes?
Short answer
B Change the S3 object key or the S3 version in the CloudFormation template before updating the CloudFormation stack.
Question
Key Takeaways
The exam tests whether you know CloudFormation detects Lambda code changes only through the Code property's S3Key/S3Version values — the trap is thinking runtime-side fixes like aliases can trigger a deployment.
CloudFormation only updates a Lambda function when the S3Bucket, S3Key, or S3Version properties in the template change, so overwriting the zip in place goes undetected. The community consensus (67% of votes) is to change the S3 object key or reference a new S3 object version before updating the stack.
Common mistake: Choosing A (Lambda alias): candidates assume an alias pointing to $LATEST will pick up new code, but an alias is a routing construct and does not change the CloudFormation template, so no update is ever triggered.
Expert Analysis
Why the Answer Is Correct
CloudFormation compares the previous and current template to decide whether a resource needs updating. For AWS::Lambda::Function, the code is identified solely by the S3Bucket, S3Key, and S3Version properties in the Code block. If you overwrite the zip file in the bucket but keep the same object key and no version ID, the template is byte-for-byte identical, so CloudFormation concludes nothing changed and skips the Lambda update. Changing the S3 object key (e.g., lambda-v2.zip) or pinning a new S3 object version forces a template diff, causing CloudFormation to deploy the new code. Comment [1] confirms this: 'You have to change the S3 Object Key and the Version every time you update the code.'
Why the Other Options Are Wrong
A is incorrect because a Lambda alias only routes invocations to a published version; it does not alter the CloudFormation template, so the stack update still sees no changes and the new zip is never deployed. C is wrong because uploading the zip to a different bucket accomplishes nothing unless you also edit the template's S3Bucket value — and at that point you are effectively doing B with extra effort. D is unrelated: a code signing configuration validates that deployment packages are signed by trusted publishers but has no effect on change detection or deployment triggering.
Community Comment Notes
Comments [1] and [3] both back answer B, with [3] noting the practical pattern of 'giving a new object key when loading the new zip file.' Comment [2] votes for A but concedes that 'B could also fit in this situation,' objecting only that manually editing the key/version is annoying for frequent deployments — a valid operational concern solved by CI/CD pipelines that inject unique keys or version IDs automatically. The vote distribution (B: 67 vs A: 33) and the technical reasoning align firmly with B as the correct answer.
Official Reference
- https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-function-code.html
- https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-updating-stacks-update-behaviors.html
These links open the official vendor documentation in a new tab.
Exam Strategy
When a CloudFormation stack 'ignores' an update, always trace the problem back to whether any property in the template actually changed. For Lambda code, only a new S3Key, S3Version, or S3Bucket value triggers redeployment — runtime features like aliases, layers, or signing configs never cause a code update on their own.
Community Votes
67% of anonymous learners picked answer B. Votes are pick records left by other test-takers — they are not the verified answer.
Discussion 3 contributions
Compiled from public community threads and reader submissions, lightly edited for clarity. Handles and vote tallies are shown as recorded, and comments reflect the views of individual contributors.
From public community threads 3
-
0bdf3af 👍 1 Answered AA. Lambda alias pointing to $LATEST will resolve this issue. B could also fit in this situation, but if deployment can happen even couple times a day it is very annoiyng to change manually the version of the lambda funtion everytime in cloudformation template
-
Shamalka 👍 1 Answered BYou have to change the S3 Object Key and the Version every time you update the code,
-
ShakthiGCP 👍 1 Answered BGiving a new object key when load the new zip file
Reader comments & corrections
No reader corrections yet — spotted an error or have a note? Share it below.
Related Analysis
Practice All DVA-C02 Questions
Access 100 questions with complete answers and detailed explanations.
View Full DVA-C02 Practice Test →