AWS Certified Developer – Associate / Question #1071 of 557

Question #1071

A developer has deployed an AWS Lambda function that is subscribed to an Amazon Simple Notification Service (Amazon SNS) topic. The developer needs to ensure that each invocation of the Lambda function is logged with its execution details in an Amazon Simple Queue Service (Amazon SQS) queue. Which solution will meet this requirement?

A

Configure the SQS queue as a dead-letter queue for the Lambda function to capture failed invocations.

B

Modify the Lambda function's code to include calls to the AWS SDK SQS SendMessage API, sending the invocation details to the SQS queue after processing each message.

C

Set up two asynchronous invocation destinations for the Lambda function: one for success events and one for failures. Assign the SQS queue as both destinations and create a CloudWatch alarm for the DestinationDeliveryFailures metric.

D

Add an asynchronous invocation destination to the Lambda function for successful executions, directing them to the SQS queue. Implement a CloudWatch alarm on the DestinationDeliveryFailures metric to monitor delivery issues.

Explanation

Option B is correct because modifying the Lambda function's code to explicitly send execution details to the SQS queue using the AWS SDK ensures that every invocation (successful or failed) is logged with precise execution details. This approach allows the developer to include custom data beyond what Lambda's built-in destinations provide.

Option A is incorrect because a dead-letter queue (DLQ) only captures failed invocations after retries, not all executions. Option C and D rely on Lambda's asynchronous invocation destinations, which log outcomes (success/failure) but not detailed execution data. Since the question requires logging execution details (e.g., internal metrics, timestamps), integrating SQS calls directly into the Lambda code (Option B) is the most reliable method.

Answer

The correct answer is: B