A developer is configuring an AWS Lambda function to process messages from an Amazon SQS standard queue. The Lambda function has a timeout of 20 seconds. The SQS queue has a default visibility timeout of 20 seconds. During testing, the developer observes that some messages are processed more than once by different Lambda executions. Which configuration change should the developer make to resolve this issue?
- Increase the default visibility timeout of the SQS queue to 120 seconds.Answer
- BIncrease the Lambda function timeout to 120 seconds.
- CDecrease the default visibility timeout of the SQS queue to 5 seconds.
- DInitialize the SQS client inside the Lambda function handler and hardcode temporary credentials to delete messages before processing.
Answer
Increase the default visibility timeout of the SQS queue to 120 seconds.
Increasing the SQS visibility timeout to 120 seconds (which is 6 times the Lambda function's timeout of 20 seconds) ensures that a message remains invisible to other consumers long enough for the Lambda function to finish processing, retry if necessary, and delete the message from the queue.
Step-by-Step Solution
Key Concept
Integrating Amazon SQS with AWS Lambda requires setting the queue's visibility timeout to at least 6 times the Lambda function's timeout to prevent duplicate processing.
Estimated Time:1m 30s