How to Reference an S3 Deployment Package for Lambda in CloudFormation?
A developer is creating a simple proof-of-concept demo by using AWS CloudFormation and AWS Lambda functions. The demo will use a CloudFormation template to deploy an existing Lambda function. The Lambda function uses deployment packages and dependencies stored in Amazon S3. The developer defined an AWS::Lambda::Function resource in a CloudFormation template. The developer needs to add the S3 bucket to the CloudFormation template. What should the developer do to meet these requirements with the LEAST development effort?
Community Votes
100% of anonymous learners picked answer D. Votes are pick records left by other test-takers — they are not the verified answer.
Community Insight
The question tests the correct Code property syntax for a Lambda function whose deployment package is in S3, with the common trap being confusion between inline code (ZipFile) and S3 references.
When deploying an existing Lambda function with CloudFormation, the function code stored in S3 must be specified using the S3Bucket and S3Key properties in the AWS::Lambda::Function resource. The community unanimously agrees that option D is correct.
Option C is the most tempting wrong answer because it mentions the S3 key but incorrectly assigns it to the ZipFile property, which is only for inline code or local files, not for S3 references.
Community Discussion (4 comments)
Comments & Corrections
No comments yet — spotted an error or have a note? Share it below.
Expert Analysis
Why the Answer Is Correct
The AWS::Lambda::Function resource has a Code property that accepts either inline code via ZipFile or a reference to an Amazon S3 object. When the Lambda function uses deployment packages and dependencies stored in S3, you must specify the S3 bucket and key in the Code property using S3Bucket and S3Key. This approach is portable and scalable, and it is the standard way to deploy existing Lambda code without embedding the code in the template. Option D directly follows this pattern, as shown in the community comment with a YAML example.
Why the Other Options Are Wrong
Option A (add the function code inline as the code property) is incorrect because the Lambda function already has a deployment package in S3; inline code would not include dependencies and violates the requirement to use the existing package. Option B (ZipFile property) is only for inline content or code that is less than 4 MB, and it does not reference the S3 package. Option C incorrectly uses ZipFile to store an S3 key, which is syntactically meaningless and will cause a validation error; ZipFile is not a placeholder for S3 paths.
Community Comment Notes
One community member (8 likes) correctly states that adding the S3Bucket and S3Key properties in the CloudFormation template is the right solution. Another comment (4 likes) links to an AWS blog about the portable way to deploy Lambda functions using CloudFormation, reinforcing the S3Bucket/S3Key approach. A detailed YAML snippet (3 likes) shows exactly how to set the Code property with S3Bucket and S3Key, confirming the correct structure. Overall, the community consistently selects D and provides clear supporting examples.
Official Reference
Exam Strategy
For any CloudFormation question involving Lambda code, first determine whether the code is inline (ZipFile) or external (S3Bucket/S3Key). If the prompt mentions S3 packages, immediately narrow your answer to the option that references the bucket and key in the Code property, and never mix ZipFile with S3 references.
Related Analysis
Practice All DVA-C02 Questions
Access 100 questions with complete answers and detailed explanations.
View Full DVA-C02 Practice Test →