DVA-C02 · Question #301
DVA-C02 Question #301: Real Exam Question with Answer & Explanation
The correct answer is D: Pass the log group's Amazon Resource Name (ARN) as an environment variable to the Lambda. Option D is correct because Lambda environment variables are the standard CloudFormation mechanism for injecting runtime configuration into a function. In the template, you reference the log group using !Ref MyLogGroup (which returns the log group name) or !GetAtt MyLogGroup.Arn
Question
A developer is creating a serverless application that uses an AWS Lambda function. The developer will use AWS CloudFormation to deploy the application. The application will write logs to Amazon CloudWatch Logs. The developer has created a log group in a CloudFormation template for the application to use. The developer needs to modify the CloudFormation template to make the name of the log group available to the application at runtime. Which solution will meet this requirement?
Options
- AUse the AWS::Include transform in CloudFormation to provide the log group's name to the
- BPass the log group's name to the application in the user data section of the CloudFormation
- CUse the CloudFormation template's Mappings section to specify the log group's name for the
- DPass the log group's Amazon Resource Name (ARN) as an environment variable to the Lambda
Explanation
Option D is correct because Lambda environment variables are the standard CloudFormation mechanism for injecting runtime configuration into a function. In the template, you reference the log group using !Ref MyLogGroup (which returns the log group name) or !GetAtt MyLogGroup.Arn and pass it as an environment variable under the Lambda's Environment.Variables property - making it accessible to the function code at runtime via process.env or os.environ.
Why the distractors fail:
- A (AWS::Include transform):
AWS::Includepulls in external CloudFormation snippets from S3 at deploy time - it's a template composition tool, not a runtime value injection mechanism. - B (User data): User data is an EC2-specific feature for bootstrapping instance startup scripts; Lambda functions have no user data concept.
- C (Mappings section): Mappings hold static, hardcoded lookup tables defined before deployment - they cannot dynamically reference a resource created elsewhere in the same template.
Memory tip: For Lambda, think "environment variables are the serverless config file." Any CloudFormation resource value you need inside a Lambda at runtime (names, ARNs, URLs) should flow in through Environment.Variables using !Ref or !GetAtt.
Topics
Community Discussion
No community discussion yet for this question.