How to Reference an S3 Deployment Package for Lambda in CloudFormation?
Short answer
D Add the relevant key and bucket to the S3Bucket and S3Key properties in the CloudFormation template.
Question
Key Takeaways
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.
Common mistake: 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.
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
- https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-function-code.html
- https://aws.amazon.com/blogs/infrastructure-and-automation/deploying-aws-lambda-functions-using-aws-cloudformation-the-portable-way/
These links open the official vendor documentation in a new tab.
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.
Community Votes
100% of anonymous learners picked answer D. Votes are pick records left by other test-takers — they are not the verified answer.
Discussion 4 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 4
-
tgv 👍 8 Answered DThe correct solution would be D, to add the S3Bucket and S3Key properties in the CloudFormation template.
-
KarBiswa 👍 4 Answered Dhttps://aws.amazon.com/blogs/infrastructure-and-automation/deploying-aws-lambda-functions-using-aws-cloudformation-the-portable-way/
-
albert_kuo 👍 3 Answered DAWSTemplateFormatVersion: '2010-09-09' Resources: MyLambdaFunction: Type: 'AWS::Lambda::Function' Properties: FunctionName: MyLambdaFunction Handler: index.handler Role: arn:aws:iam::123456789012:role/execution_role Code: S3Bucket: my-lambda-functions-bucket S3Key: path/to/my-deployment-package.zip Runtime: python3.8 Timeout: 300 MemorySize: 128
-
65703c1 👍 1 Answered DD is the correct answer.
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 →