Soru

Zorluk: OrtaMessage-Based Integration using Amazon SQS and SNS

An application uses an AWS Lambda function to process messages from an Amazon SQS standard queue. The Lambda function has its timeout configured to 33 minutes. During peak traffic, the developer notices that many messages are processed multiple times by parallel Lambda invocations, even though all Lambda executions finish successfully. The SQS queue has a Default Visibility Timeout of 3030 seconds. Which configuration change should the developer make to resolve this issue?

  1. A
    Configure the SQS queue as a FIFO queue and enable content-based deduplication.
  2. B
    Increase the Lambda function's timeout configuration to 1818 minutes.
  3. Increase the SQS queue's Default Visibility Timeout to 1818 minutes.Cevap
  4. D
    Redeploy the Lambda function inside a private VPC subnet without a NAT Gateway.

Cevap

Increase the SQS queue's Default Visibility Timeout to 1818 minutes.
To prevent duplicate message processing when SQS is used as an event source for AWS Lambda, the queue's visibility timeout must be configured to at least 66 times the timeout of the Lambda function. With a Lambda timeout of 33 minutes, the visibility timeout should be set to at least 1818 minutes to ensure that the message is not visible to other consumers during execution and retries.

Adım Adım Çözüm

1
Analyze the relationship between the SQS visibility timeout and the Lambda timeout.
The current SQS visibility timeout is 3030 seconds, while the Lambda function timeout is 33 minutes (180180 seconds).
Since the Lambda execution can take longer than the visibility timeout, SQS assumes the processing failed and makes the message visible again before the Lambda function finishes.
2
Determine the recommended SQS visibility timeout for Lambda integration.
AWS recommends setting the SQS queue's visibility timeout to at least 66 times the timeout of the integrated Lambda function.
This 6×6\times multiplier provides sufficient time for the Lambda service to execute the function and perform retries in case of transient errors without the messages reappearing in the queue prematurely.
3
Calculate the new visibility timeout.
33 minutes ×6=18\times 6 = 18 minutes.
Increasing the Default Visibility Timeout to 1818 minutes ensures that messages are not processed concurrently by multiple Lambda invocations.

Anahtar Kavram

SQS Visibility Timeout configuration when integrated with AWS Lambda as an event source.
Bu soruyu puanla