A developer wants to log important events during a Lambda invocation and include a unique identifier for the specific invocation. Which approach satisfies this requirement?
Choose an answer
Tap an option to check your answer.
Correct answer: Get the request ID from the AWS request ID field in the context object, and write logs to standard output..
Why this is the answer
The correct approach is to get the request ID from the context object and write logs to standard output. Each AWS Lambda invocation has a unique request ID, accessible via context.awsrequestid in most runtimes. This ID is crucial for correlating logs from a specific invocation. Writing logs to standard output (e.g., console.log in Node.js, print() in Python) automatically sends them to Amazon CloudWatch Logs, where they are associated with the Lambda function and the specific invocation's log stream. Incorrect options: Getting the request ID from the event object is incorrect because the event object contains input data to the Lambda function, not invocation metadata like the request ID. Writing logs to a file is incorrect because Lambda's execution environment is ephemeral and read-only for most of the file system. Logs written to local files would be lost and not integrated with CloudWatch.
Pass your exam — without the endless answer hunt
Get every verified question and explanation for this exam in one place, and save hours of prep. 1,000+ certifications · 20+ languages · free to start.
Pass your exam faster → No card needed