AWS Certified Developer – Associate (DVA-C02)Development with AWS ServicesMedium

A developer is writing an AWS Lambda function that processes messages from an Amazon SQS queue. The function is occasionally failing due to external API rate limits. The developer wants to ensure that failed messages are automatically retried with an exponential backoff strategy without writing custom retry logic in the Lambda function. What is the most efficient way to achieve this?

  1. AConfigure the Lambda function's asynchronous invocation settings to include a `Maximum retry attempts` and a `Destination` for failed invocations.
  2. BConfigure the Lambda function's retry attempts to 0 and implement custom retry logic within the Lambda code with a `setTimeout`.
  3. CConfigure the SQS queue's `RedrivePolicy` with a `maxReceiveCount` greater than 1 and a `deadLetterTargetArn`.
  4. DSet the SQS queue's `MaximumReceives` parameter to 1 and configure a Dead-Letter Queue (DLQ) for failed messages.
Show answer & explanation

Correct answer: C. Configure the SQS queue's `RedrivePolicy` with a `maxReceiveCount` greater than 1 and a `deadLetterTargetArn`.

Configuring the SQS queue's `RedrivePolicy` with a `maxReceiveCount` greater than 1 and a `deadLetterTargetArn` allows SQS to automatically retry messages that fail processing by the Lambda function, delivering them back to the source queue with an exponential backoff, before moving them to a DLQ if retries are exhausted.

Why the other options are wrong

  • A. Lambda's asynchronous invocation retries apply when Lambda itself fails to invoke (e.g., due to throttling). For SQS as an event source, SQS manages retries for messages that fail processing by the Lambda function.
  • B. This approach requires custom retry logic, which the question explicitly seeks to avoid for efficiency, and `setTimeout` is not an exponential backoff strategy.
  • D. Setting `MaximumReceives` to 1 means the message will immediately go to the DLQ after the first failure, preventing automatic retries by SQS.

SQS Redrive Policy

A configuration on an Amazon SQS queue that specifies how messages that fail to be processed by consumers should be handled, including automatic retries and moving to a Dead-Letter Queue (DLQ).

  • Automatically retries messages that fail processing.
  • Utilizes an exponential backoff delay before redelivering messages.
  • Moves messages to a DLQ after a specified number of retries (`maxReceiveCount`).

Memory trick: SQS RedrivePolicy is the reliable road for retries.

More Development with AWS Services questions