Soru

Zorluk: OrtaServerless Development with AWS Lambda

A developer is troubleshooting a serverless application where an AWS Lambda function is triggered by an Amazon SQS queue to process incoming batch jobs. The Lambda function has a configured timeout of 22 minutes. The Amazon SQS queue has a visibility timeout of 3030 seconds. During testing, the developer observes that messages are frequently being processed multiple times by parallel Lambda invocations before being successfully deleted.

Which configuration change will resolve this issue?

  1. Increase the visibility timeout of the Amazon SQS queue to at least 1212 minutes.Cevap
  2. B
    Increase the timeout of the AWS Lambda function to 1212 minutes.
  3. C
    Deploy the AWS Lambda function inside a private VPC subnet with no NAT Gateway.
  4. D
    Switch the SQS integration to use API Gateway Lambda Proxy integration to manage message routing.

Cevap

Increase the visibility timeout of the Amazon SQS queue to at least 1212 minutes.
Increasing the visibility timeout of the Amazon SQS queue to at least 1212 minutes is the correct action. AWS recommends configuring the visibility timeout of the source SQS queue to at least 66 times the timeout of the Lambda function. Since the function has a timeout of 22 minutes, the queue's visibility timeout must be set to at least 1212 minutes to ensure messages do not become visible to other concurrent invocations while the current execution is still running.

Adım Adım Çözüm

1
Identify the relationship between the Lambda function timeout and the SQS visibility timeout.
The Lambda function timeout is 22 minutes (120120 seconds), whereas the SQS visibility timeout is only 3030 seconds.
If the SQS visibility timeout is shorter than the Lambda function's processing time, the message becomes visible to other consumers before the current Lambda function finishes processing it, leading to duplicates.
2
Apply the AWS recommended formula for SQS visibility timeout when integrating with Lambda.
The SQS visibility timeout should be configured to at least 66 times the Lambda function timeout plus the batch window.
Calculating 6×2 minutes=12 minutes6 \times 2 \text{ minutes} = 12 \text{ minutes} ensures that the queue allows enough time for the Lambda function to process the batch and retry if necessary before making the message visible again.

Anahtar Kavram

Amazon SQS Visibility Timeout alignment with AWS Lambda Timeout
Bu soruyu puanla