Question

Difficulty: MediumMessage-Based Integration using Amazon SQS and SNS

A developer is implementing a serverless worker application. An Amazon SQS standard queue triggers an AWS Lambda function to process inventory updates. The Lambda function has its timeout configured to 45 seconds45\text{ seconds}, and the SQS queue has a visibility timeout of 30 seconds30\text{ seconds}. During peak hours, the developer notices that some inventory updates are processed multiple times, resulting in incorrect stock counts in the database. Which configuration change will resolve this issue?

  1. A
    Decrease the Amazon SQS queue's visibility timeout to 15 seconds15\text{ seconds} to ensure that failed messages are returned to the queue more quickly for reprocessing.
  2. Increase the Amazon SQS queue's visibility timeout to at least 270 seconds270\text{ seconds} to meet the recommended value of at least 6 times6\text{ times} the Lambda function's timeout.Answer
  3. C
    Increase the AWS Lambda function's timeout to 90 seconds90\text{ seconds} while keeping the SQS queue's visibility timeout at 30 seconds30\text{ seconds} to allow the function more time to complete its execution.
  4. D
    Configure the Amazon SQS queue as a FIFO (First-In-First-Out) queue and set the Lambda function concurrency limit to 11 to guarantee ordered single-threaded processing.

Answer

Increase the Amazon SQS queue's visibility timeout to at least 270 seconds270\text{ seconds} to meet the recommended value of at least 6 times6\text{ times} the Lambda function's timeout.
The correct answer is to increase the Amazon SQS queue's visibility timeout to at least 270 seconds270\text{ seconds}. When an Amazon SQS queue is configured as an event source for an AWS Lambda function, the recommended visibility timeout is at least 6 times6\text{ times} the timeout of the Lambda function. Since the Lambda function timeout is 45 seconds45\text{ seconds}, the SQS queue's visibility timeout must be set to at least 270 seconds270\text{ seconds} (6×45 seconds6 \times 45\text{ seconds}). If the visibility timeout is shorter than the Lambda execution time, SQS may make the messages visible to other concurrent Lambda invocations while the original execution is still running, resulting in duplicate processing.

Step-by-Step Solution

1
Analyze the relationship between SQS visibility timeout and Lambda function timeout.
Identify that when using SQS as an event source, the SQS visibility timeout must be set to at least 6 times6\text{ times} the Lambda function's timeout.
This buffer prevents SQS from redelivering a message while the Lambda function is still actively processing the batch or performing retries.
2
Calculate the required minimum SQS visibility timeout based on the configuration.
Multiply the Lambda timeout of 45 seconds45\text{ seconds} by 66, yielding 270 seconds270\text{ seconds} (45 s×6=270 s45\text{ s} \times 6 = 270\text{ s}).
This determines the minimum safe duration during which the message remains invisible to other consumers.
3
Evaluate the proposed options against the calculated value.
Increasing the SQS queue's visibility timeout to at least 270 seconds270\text{ seconds} is the correct configuration change.
It aligns with the AWS-recommended architecture to eliminate duplicate processing caused by premature visibility timeout expiration.

Key Concept

SQS visibility timeout configuration when integrated as a Lambda event source
Estimated Time:1m 30s
Rate this question