AWS Certified Developer – Associate (DVA-C02)Troubleshooting and MonitoringMedium
A developer is building a serverless application using AWS Lambda and Amazon SQS. They have configured a Lambda function to process messages from an SQS queue. Recently, they've observed that some messages are being processed multiple times, even though the Lambda function successfully processes them and returns without error. The SQS queue is standard, and the Lambda function has a batch size of 10. What is the MOST likely reason for the duplicate processing?
- AThe Lambda function is configured with an insufficient amount of memory, causing intermittent failures.
- BThe SQS queue's visibility timeout is set too low for the Lambda function's processing time.
- CThe Lambda function's execution role does not have `sqs:DeleteMessage` permissions.
- DThe SQS queue is configured as a FIFO queue, which inherently delivers messages multiple times.
Show answer & explanationAnswer & explanation
Correct answer: B. The SQS queue's visibility timeout is set too low for the Lambda function's processing time.
If the SQS visibility timeout is too low, messages can become visible again in the queue before the Lambda function has a chance to delete them after successful processing. This leads to other Lambda invocations picking up and processing the same messages again.
Why the other options are wrong
- A. Insufficient memory would typically cause the Lambda function to fail (e.g., 'Out of memory' error) or slow down, not to process successfully and then have duplicates appear due to SQS behavior.
- C. If `sqs:DeleteMessage` permissions were missing, messages would never be deleted, leading to infinite processing, not just duplicate processing after successful completion.
- D. FIFO queues guarantee exactly-once processing (no duplicates) and strict ordering, so this option contradicts the observed behavior of duplicates.
SQS Visibility Timeout
The SQS visibility timeout is the period during which a message is hidden from other consumers after it's received by one, preventing duplicate processing.
- Must be longer than the consumer's processing time.
- If too short, messages reappear and can be processed again.
- Can be extended programmatically using `ChangeMessageVisibility`.
Memory trick: SQS visibility is key to avoiding message déjà vu.