Q89 — AWS DVA-C02 Ch.1

Question 89 of 100 | ← Chapter 1

A developer is developing an AWS Lambda function. The developer wants to log critical events that occur while the Lambda function executes. The developer wants to include a unique identifier to associate these events with a specific function invocation. The developer added the following code to the Lambda function: Function handler (event, context) {}. Which solution meets this requirement?

Correct Answer: A. Retrieve the request identifier from the AWS Request ID field of the context object. Configure the application to write logs to standard output.

Explanation

In an AWS Lambda function, the awsRequestId field of the context object provides a unique request identifier associated with a specific function invocation. Therefore, the correct solution is to retrieve the request identifier from the AWS Request ID field of the context object. Function handler(event, context){ const requestId = context.awsRequestId; // Use requestId to log critical events}