ExamGecko
Question list
Search
Search

List of questions

Search

Related questions











Question 170 - DVA-C02 discussion

Report
Export

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?

A.
Use the AWS:lnclude transform in CloudFormation to provide the log group's name to the application
Answers
A.
Use the AWS:lnclude 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.
Answers
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.
Answers
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
Answers
D.
Pass the log group's Amazon Resource Name (ARN) as an environment variable to the Lambda function
Suggested answer: D

Explanation:

CloudFormation and Lambda Environment Variables:

CloudFormation is an excellent tool to manage infrastructure as code, including the log group resource.

Lambda functions can access environment variables at runtime, making them a suitable way to pass configuration information like the log group ARN.

CloudFormation Template Modification:

In your CloudFormation template, define the log group resource.

In the Lambda function resource, add anEnvironmentsection:

YAML

Environment:

Variables:

LOG_GROUP_ARN: !Ref LogGroupResourceName

Use codewith caution.

content_copy

The!Refintrinsic function retrieves the log group's ARN, which CloudFormation generates during stack creation.

Using the ARN in Your Lambda Function:

Within your Lambda code, access theLOG_GROUP_ARNenvironment variable.

Configure your logging library (e.g., Python'sloggingmodule) to send logs to the specified log group.

AWS Lambda Environment Variables:https://docs.aws.amazon.com/lambda/latest/dg/configuration-envvars.html

CloudFormation !Ref Intrinsic Function:https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-ref.html

asked 16/09/2024
Emily Luijten
46 questions
User
Your answer:
0 comments
Sorted by

Leave a comment first