Answer - B.
This is also mentioned in the AWS Documentation.
Any Lambda function invoked asynchronously is retried twice before the event is discarded.
If the retries fail and you're unsure why use Dead Letter Queues (DLQ) to direct unprocessed events to an Amazon SQS queue to analyze the failure.
Option A is incorrect since the metrics will only give the rate at which the function is executing.
But it cannot help debug the actual error.
Option C is incorrect because CloudWatch Events cannot help to handle failed or discarded events.
Option D is incorrect since this is only used for API monitoring.
For more information on dead letter queues with AWS Lambda, please refer to the below URL-
https://docs.aws.amazon.com/lambda/latest/dg/dlq.html
When a Lambda function is processed asynchronously, AWS Lambda service will not wait for the function's response before sending a response back to the calling service or application. Therefore, if the Lambda function fails, the calling service or application will not be able to know that the function has failed. To address this issue, you need to implement a mechanism to monitor and handle failed executions of the Lambda function.
One way to accomplish this is by assigning a Dead Letter Queue (DLQ). A DLQ is a queue where AWS Lambda sends events that cannot be processed. When you configure a DLQ for a Lambda function, if the function fails, the event that triggered the function will be sent to the DLQ instead of being lost. You can then use tools like Amazon Simple Notification Service (SNS) or Amazon Simple Queue Service (SQS) to receive notifications or messages from the DLQ and take further actions, such as retrying the function, analysing the failure, or processing the event at a later time.
AWS CloudWatch is a monitoring service that provides data and insights into your AWS resources and applications. You can use CloudWatch to monitor and analyze metrics, logs, and events related to your Lambda function. For example, you can set up CloudWatch Alarms to receive notifications when certain metrics, such as the number of errors or the duration of the function, exceed a threshold. However, CloudWatch alone cannot handle failed executions of a Lambda function.
CloudWatch Events is a service that enables you to respond to events that occur in your AWS environment. You can use CloudWatch Events to trigger automated workflows, such as sending notifications, running Lambda functions, or invoking APIs, based on specific events or patterns. For example, you can set up a CloudWatch Event rule to trigger a Lambda function whenever a failed execution of your Lambda function is detected. However, CloudWatch Events alone cannot handle failed executions of a Lambda function.
AWS CloudTrail is a service that logs and monitors API activity in your AWS account. You can use CloudTrail to track changes to your AWS resources, such as Lambda functions, and investigate security incidents, troubleshoot issues, or meet compliance requirements. However, CloudTrail logs do not provide real-time visibility into the execution of a Lambda function, and they do not provide a mechanism to handle failed executions.
Therefore, the correct answer for this question is B: Assign a dead letter queue. By assigning a DLQ to your Lambda function, you can ensure that failed executions are not lost and can be processed at a later time.