DVA-C02 · Question #486
A developer is testing an AWS Lambda function that has an event source of an Amazon Simple Queue Service (Amazon SQS) queue. The developer notices that some of the messages the Lambda function process
The correct answer is B. Increase the visibility timeout of the SQS queue.. When a Lambda function takes longer to process an SQS message than the queue's visibility timeout, SQS makes the message visible again, causing it to be processed twice; increasing the visibility timeout resolves this.
Question
A developer is testing an AWS Lambda function that has an event source of an Amazon Simple Queue Service (Amazon SQS) queue. The developer notices that some of the messages the Lambda function processes re-appear in the queue while the messages are being processed. The developer must correct this behavior. Which solution will meet this requirement?
Options
- AIncrease the timeout of the Lambda function.
- BIncrease the visibility timeout of the SQS queue.
- CIncrease the memory allocation of the Lambda function.
- DIncrease the batch size in the event source mapping.
How the community answered
(38 responses)- A13% (5)
- B74% (28)
- C5% (2)
- D8% (3)
Why each option
When a Lambda function takes longer to process an SQS message than the queue's visibility timeout, SQS makes the message visible again, causing it to be processed twice; increasing the visibility timeout resolves this.
Increasing the Lambda function timeout only extends how long Lambda is allowed to run; it does not affect the SQS visibility timeout, so the message can still become visible again before Lambda finishes.
The SQS visibility timeout must be set to at least as long as the Lambda function's maximum processing time; if Lambda has not deleted the message before the visibility timeout expires, SQS assumes the processing failed and makes the message available to consumers again, causing re-processing.
Memory allocation affects Lambda execution speed for compute-bound tasks but does not change the SQS visibility timeout or prevent messages from reappearing.
Increasing the batch size causes Lambda to process more messages per invocation but does not change the visibility timeout, so all messages in a batch can still reappear if processing takes longer than the timeout.
Concept tested: SQS visibility timeout alignment with Lambda processing time
Source: https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-visibility-timeout.html
Community Discussion
No community discussion yet for this question.