Soru

Zorluk: KolayMessage-Based Integration using Amazon SQS and SNS

A developer is configuring an AWS Lambda function to process user upload notifications from an Amazon SQS standard queue. The Lambda function timeout is configured to 3030 seconds. However, the SQS queue's default visibility timeout is set to 1010 seconds. During performance tests, the developer notices that some upload messages are processed multiple times by different Lambda instances. Which action should the developer take to resolve this duplication issue?

  1. A
    Decrease the default visibility timeout of the Amazon SQS queue to 55 seconds.
  2. B
    Increase the Lambda function's timeout configuration to 180180 seconds while leaving the queue's visibility timeout at 1010 seconds.
  3. Increase the default visibility timeout of the Amazon SQS queue to at least 180180 seconds.Cevap
  4. D
    Hardcode temporary AWS credentials directly in the Lambda function's code to initialize the Amazon SQS SDK client and delete the message immediately upon invocation.

Cevap

Increase the default visibility timeout of the Amazon SQS queue to at least 180180 seconds.
Increasing the SQS visibility timeout to at least 6 times the Lambda function's timeout (180180 seconds) ensures the Lambda function has enough time to finish processing the message and delete it from the queue before the message becomes visible to other concurrent Lambda invocations.

Adım Adım Çözüm

1
Identify the cause of duplicate message processing.
The Lambda function's timeout of 3030 seconds is longer than the SQS queue's visibility timeout of 1010 seconds.
When processing takes longer than the visibility timeout, SQS makes the message visible to other consumers, leading to duplicate processing.
2
Apply the AWS recommendation for SQS visibility timeout when integrated with AWS Lambda.
The visibility timeout of the SQS queue should be configured to at least 6 times the timeout of the Lambda function.
This formula guarantees that even with retries or batch processing delays, the message remains hidden until Lambda finishes.
3
Calculate the required SQS visibility timeout value.
The minimum recommended visibility timeout is 6×30=1806 \times 30 = 180 seconds.
Applying the multiplication factor gives the correct configuration value.

Anahtar Kavram

SQS Visibility Timeout configuration when integrated with AWS Lambda
Tahmini Süre:1m 0s
Bu soruyu puanla