A developer is implementing a serverless worker application. An Amazon SQS standard queue triggers an AWS Lambda function to process inventory updates. The Lambda function has its timeout configured to , and the SQS queue has a visibility timeout of . During peak hours, the developer notices that some inventory updates are processed multiple times, resulting in incorrect stock counts in the database. Which configuration change will resolve this issue?
- ADecrease the Amazon SQS queue's visibility timeout to to ensure that failed messages are returned to the queue more quickly for reprocessing.
- Increase the Amazon SQS queue's visibility timeout to at least to meet the recommended value of at least the Lambda function's timeout.Answer
- CIncrease the AWS Lambda function's timeout to while keeping the SQS queue's visibility timeout at to allow the function more time to complete its execution.
- DConfigure the Amazon SQS queue as a FIFO (First-In-First-Out) queue and set the Lambda function concurrency limit to to guarantee ordered single-threaded processing.
Answer
Increase the Amazon SQS queue's visibility timeout to at least to meet the recommended value of at least the Lambda function's timeout.
The correct answer is to increase the Amazon SQS queue's visibility timeout to at least . When an Amazon SQS queue is configured as an event source for an AWS Lambda function, the recommended visibility timeout is at least the timeout of the Lambda function. Since the Lambda function timeout is , the SQS queue's visibility timeout must be set to at least (). If the visibility timeout is shorter than the Lambda execution time, SQS may make the messages visible to other concurrent Lambda invocations while the original execution is still running, resulting in duplicate processing.
Step-by-Step Solution
Key Concept
SQS visibility timeout configuration when integrated as a Lambda event source
Estimated Time:1m 30s