AWS Certified Developer – Associate (DVA-C02) — Question 304
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?
Answer options
- A. Use the AWS::Include transform in CloudFormation to provide the log group's name to the application.
- B. Pass the log group's name to the application in the user data section of the CloudFormation template.
- C. Use the CloudFormation template's Mappings section to specify the log group's name for the application.
- D. Pass the log group's Amazon Resource Name (ARN) as an environment variable to the Lambda function.
Correct answer: D
Explanation
Passing the log group's ARN as an environment variable is the standard way to inject resource identifiers into an AWS Lambda function at runtime. User data is only applicable to Amazon EC2 instances, not serverless Lambda functions. The AWS::Include transform is for importing external template snippets, and the Mappings section is for static lookups, making them incorrect for dynamically passing a runtime resource name.