Question

Difficulty: MediumMessage-Based Integration using Amazon SQS and SNS

A developer is implementing a food delivery platform where courier dispatch updates are processed using an Amazon SQS standard queue. An AWS Lambda function is configured to consume messages from the queue with a batch size of 1010 messages and a function timeout of 1515 seconds. During peak loads, some courier assignments are processed multiple times by different Lambda execution environments, even though the Lambda function executes successfully and returns within 1212 seconds. Which of the following configuration changes will resolve this issue?

  1. Increase the SQS queue's visibility timeout to at least 9090 seconds.Answer
  2. B
    Increase the Lambda function's timeout to 9090 seconds while keeping the SQS visibility timeout at 3030 seconds.
  3. C
    Decrease the SQS queue's visibility timeout to 1010 seconds to allow faster reprocessing of messages.
  4. D
    Configure the AWS SDK client inside the Lambda function using hardcoded, long-term IAM access keys.

Answer

Increase the Amazon SQS queue's visibility timeout to at least 9090 seconds.
The correct answer is to increase the SQS queue's visibility timeout to at least 9090 seconds. AWS recommends setting the visibility timeout of a source SQS queue to at least 66 times the timeout of the consuming Lambda function. With a 1515-second Lambda timeout, the SQS visibility timeout must be set to at least 9090 seconds (15 seconds×615 \text{ seconds} \times 6) to allow sufficient time for processing and retries without messages becoming visible to other instances.

Step-by-Step Solution

1
Identify the cause of duplicate processing under peak load.
The Lambda function timeout is 1515 seconds. If the default SQS visibility timeout (3030 seconds) is too low relative to peak processing and retries, other Lambda workers pull the same messages before the current invocation deletes them.
This occurs because SQS makes the message visible again once the visibility timeout expires.
2
Apply the AWS recommended best practice formula for SQS-to-Lambda integration.
The visibility timeout of the source SQS queue should be set to at least 66 times the timeout of the consumer Lambda function (15 seconds×6=90 seconds15 \text{ seconds} \times 6 = 90 \text{ seconds}).
This buffer prevents other consumers from receiving and processing messages while the current Lambda execution handles the batch and potential transient errors.

Key Concept

Amazon SQS Visibility Timeout for Lambda Event Sources
Rate this question