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?

  1. Create a new Lambda function alias before updating the CloudFormation stack.
  2. Change the S3 object key or the S3 version in the CloudFormation template before updating the CloudFormation stack. Source Reference Answer
  3. Upload the zipped source code to another S3 bucket before updating the CioudFormation stack.
  4. Associate a cade signing configuration with the Lambda function before updating the CloudFormation stack.

Community Votes

B
67%
A
33%

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)

Shamalka 👍 1 Selected: B
You have to change the S3 Object Key and the Version every time you update the code,
0bdf3af 👍 1 Selected: A
A. 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
ShakthiGCP 👍 1 Selected: B
Giving a new object key when load the new zip file

Comments & Corrections

No comments yet — spotted an error or have a note? Share it below.

Log in to comment, report an error, or add a note about this question.

Submitted for moderation before publishing. Keep it helpful and respectful.

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 →

← Back to DVA-C02 Study Guide