Point CodeUri at the local folder and deploy with sam deploy, or package the folder and use cloudformation package plus deploy
A developer is using the AWS Serverless Application Model (AWS SAM) to create a prototype for an AWS Lambda function. The AWS SAM template contains an AWS::Serverless::Function resource that has the CodeUri property that points to an Amazon S3 location. The developer wants to identify the correct commands for deployment before creating a CI/CD pipeline. The developer creates an archive of the Lambda function code named package.zip. The developer uploads the .zip file archive to the S3 location specified in the CodeUri property. The developer runs the sam deploy command and deploys the Lambda function. The developer updates the Lambda function code and uses the same steps to deploy the new version of the Lambda function. The sam deploy command fails and returns an error of no changes to deploy. Which solutions will deploy the new version? (Choose two.)
Community Votes
80% of anonymous learners picked answer CE. Votes are pick records left by other test-takers — they are not the verified answer.
Community Insight
Both correct paths start by repointing CodeUri at the local application code folder, because that is what makes the change visible to the tooling: SAM then hashes and packages the code itself during sam deploy (C), or the cloudformation package command performs that packaging explicitly before deployment (E). Using aws cloudformation update-stack directly against a template whose CodeUri still points at the unchanged S3 object would fail in the same way, because the underlying artifact has not changed, and update-stack-instances in option B applies to stack instance groups across accounts rather than deploying code. Option A therefore does not address the cause.
The sam deploy command reports no changes because the CodeUri points at an S3 location whose contents are unchanged as far as CloudFormation is concerned; SAM cannot see that the code behind that fixed S3 key has been replaced. Pointing CodeUri at the local application folder lets SAM compute a content hash, package the code, and upload it as part of sam deploy, so the change is detected. The equivalent alternative is to package the local folder explicitly with the cloudformation package command and then deploy the generated template, which also produces the updated artifact.
Using the aws cloudformation update-stack command instead of sam deploy (A) — the failure is caused by the unchanged S3 artifact behind the CodeUri, so invoking CloudFormation directly still sees no change to the code location and the deployment remains a no-op. Using the aws cloudformation update-stack-instances command (B) — that operation updates stack instances across accounts or Regions using a prepared stack set or change set; it does not package or deploy updated function code and cannot resolve the unchanged artifact problem. The key insight both correct options share is repointing CodeUri at the local folder so packaging happens during deployment.
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
The root cause is that the CodeUri points at a fixed Amazon S3 location, so after uploading a new.zip to that same key CloudFormation still sees an unchanged template and reports no changes to deploy. Repointing the CodeUri property at the local application code folder fixes this, because the tooling then derives a content hash from the local files and packages and uploads the code as part of the deployment. Using the sam deploy command with a local CodeUri performs that hashing, packaging, and upload automatically and is the simplest path (C). The second correct path is to repoint CodeUri at the local folder and run the aws cloudformation package command, which performs the packaging and uploads it, followed by the aws cloudformation deploy command to deploy the resulting template (E). C and E are the correct combination.Why the Other Options Are Wrong
A uses the aws cloudformation update-stack command instead of sam deploy. The problem is not which deployment command is invoked but that the template's CodeUri still references the same S3 object whose content has been replaced without a changed location; invoking CloudFormation directly therefore produces the same no-changes result. B uses the aws cloudformation update-stack-instances command. That operation updates stack instances across accounts or Regions from an existing prepared set or change set; it does not package or deploy updated function code, so it cannot resolve the unchanged artifact problem. C and E are correct.Community Comment Notes
Community voted C,E (80), with A,C a 20 percent minority. trungtd explained both halves of the correct answer, that updating CodeUri to reference the local application code folder lets AWS SAM handle packaging and uploading the code to S3 during sam deploy, and that the cloudformation package command performs the equivalent packaging before deployment. jamesf confirmed that both C and E deploy the updated code reliably by ensuring changes are detected. awsaz favored A and C, but using the cloudformation update-stack command against a template whose CodeUri still points at the unchanged S3 object does not address the cause of the no-changes result.Official Reference
Related Analysis
Practice All DOP-C02 Questions
Access 85 questions with complete answers and detailed explanations.
View Full DOP-C02 Practice Test →