A developer is configuring a serverless workflow where an Amazon SQS queue triggers an AWS Lambda function to process inventory updates. The Lambda function has its timeout set to 2 minutes. During testing, the developer notices that some messages are being processed multiple times by different Lambda invocations. Which configuration change will resolve this issue?
- ADecrease the Lambda function's timeout to 10 seconds to ensure the function finishes before the SQS visibility timeout.
- Configure the SQS queue's visibility timeout to be at least 12 minutes (six times the Lambda function's timeout).Answer
- CEnable long polling on the SQS queue by setting the ReceiveMessageWaitTimeSeconds parameter to 20 seconds.
- DIncrease the DelaySeconds configuration on the SQS queue to match the Lambda function's execution time.
Answer
Configure the SQS queue's visibility timeout to be at least 12 minutes (six times the Lambda function's timeout).
The correct option proposes configuring the SQS queue's visibility timeout to be at least 12 minutes (six times the Lambda function's timeout of 2 minutes). AWS best practices dictate that the visibility timeout of the source queue must be set to at least 6 times the timeout of the Lambda function to prevent messages from reappearing in the queue and being processed again while the current Lambda invocation is still running or retrying.
Step-by-Step Solution
Key Concept
SQS visibility timeout integration with AWS Lambda