A developer is using an AWS Lambda function to process messages from an Amazon SQS standard queue. The Lambda function processes each message by calling a third-party API, which usually takes but can take up to under high load. The SQS queue's visibility timeout is configured to , and the Lambda function's timeout is set to . The developer notices that when the third-party API is slow, messages are processed multiple times, resulting in duplicate database entries. Which change should the developer make to resolve this duplicate processing issue?
- Increase the SQS queue's visibility timeout to or more.Cevap
- BDecrease the SQS queue's visibility timeout to to match the average API response time.
- CIncrease the Lambda function's timeout to while keeping the SQS visibility timeout at .
- DInitialize the AWS SDK client inside the Lambda handler using hardcoded AWS access keys.
Cevap
Increase the SQS queue's visibility timeout to or more.
The correct answer is to increase the SQS queue's visibility timeout to or more. If the queue's visibility timeout is shorter than the Lambda function's timeout, SQS will make the message visible to other consumers while the active execution is still running. AWS recommends configuring the queue's visibility timeout to at least 6 times the Lambda function's timeout to ensure proper handling and retries.
Adım Adım Çözüm
Anahtar Kavram
SQS Visibility Timeout vs. Consumer Processing Time