A company has an AWS Lambda function that processes messages from an Amazon SQS queue. The function sometimes fails due to transient errors. The developer wants to ensure that failed messages are retried automatically and then sent to a dead-letter queue after three failed attempts. How should the developer configure this?
This is the correct approach for handling message failures when an SQS queue triggers a Lambda function. By configuring a redrive policy on the SQS queue itself, along with a dead-letter queue and a `maxReceiveCount` of 3, SQS will automatically manage message retries. If the Lambda function fails to process a message three times, SQS will move that message to the specified dead-letter queue for later inspection and reprocessing, ensuring no messages are lost indefinitely.
Why this answer
Amazon SQS supports a redrive policy that automatically moves messages to a dead-letter queue (DLQ) after a specified number of receive attempts. By setting maxReceiveCount to 3, the SQS queue will retry delivering the message to the Lambda function up to three times (including the initial attempt). After three failed processing attempts, the message is automatically sent to the configured DLQ.
This approach decouples retry logic from the Lambda function itself and leverages SQS's built-in reliability features.
Exam trap
The trap here is that candidates often confuse Lambda's asynchronous invocation DLQ (for events like S3 or SNS) with the SQS redrive policy, mistakenly thinking they can configure retries and DLQ on the Lambda function itself rather than on the SQS queue.
How to eliminate wrong answers
Option A is wrong because Lambda functions do not have a configurable retry count for SQS-triggered invocations; Lambda's built-in DLQ is for asynchronous invocations (e.g., from S3 or SNS), not for SQS event source mappings, and setting retry attempts on the function itself is not supported. Option B is wrong because setting reserved concurrency to 0 would prevent the Lambda function from executing at all, causing all messages to fail immediately, and the DLQ on the function is again irrelevant for SQS-triggered invocations. Option D is wrong because SNS topics are not used to retry or manage DLQ behavior for SQS-triggered Lambda functions; the retry and DLQ logic must be configured on the SQS queue itself, not via an SNS topic.