How to Update Lambda Code in CloudFormation When the S3 Zip Changes?
A developer is implementing a serverless application by using AWS CloudFormation to provision Amazon S3 web hosting. Amazon API Gateway, and AWS Lambda functions. The Lambda function source code is zipped and uploaded to an S3 bucket. The S3 object key of the zipped source code is specified in the Lambda resource in the CloudFormation template. The developer notices that there are no changes in the Lambda function every time the CloudFormation stack is updated. How can the developer resolve this issue?
Community Votes
67% of anonymous learners picked answer B. Votes are pick records left by other test-takers — they are not the verified answer.
Community Insight
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.
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.
Community Discussion (3 comments)
Comments & Corrections
No comments yet — spotted an error or have a note? Share it below.
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
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.
Related Analysis
Practice All DVA-C02 Questions
Access 100 questions with complete answers and detailed explanations.
View Full DVA-C02 Practice Test →