Question #1117
A mobile app allows users to upload videos to an Amazon S3 bucket. The bucket is configured to send object creation events to an Amazon SQS standard queue. An AWS Lambda function is triggered by the SQS queue to process each video and send a confirmation SMS to the user. Users report receiving multiple SMS messages for each upload. Investigation reveals that the Lambda function is processing SQS messages multiple times. What should be done to resolve this with the LEAST operational overhead?
Configure long polling for the SQS queue by setting the ReceiveMessage wait time to 20 seconds.
Replace the SQS standard queue with an SQS FIFO queue and enable content-based deduplication.
Adjust the visibility timeout of the SQS queue to exceed the sum of the Lambda function's timeout and the batch window duration.
Update the Lambda function to delete messages from the SQS queue immediately upon retrieval, prior to processing.
Explanation
The issue arises because SQS standard queues provide 'at-least-once' delivery, and messages may reappear if the Lambda function doesn't delete them before the visibility timeout expires. If the Lambda function's processing time exceeds the visibility timeout, the message becomes visible again, leading to reprocessing and duplicate SMS messages.
- Option C resolves this by ensuring the visibility timeout is longer than the Lambda function's timeout plus batch window duration. This prevents the message from being reprocessed before Lambda completes its task, eliminating duplicates.
- Option A (long polling) reduces empty responses but doesn't address reprocessing.
- Option B (FIFO queue) ensures exactly-once processing but requires reconfiguring S3 event notifications and queue settings, adding operational complexity.
- Option D risks losing messages if processing fails after deletion.
Key takeaway: Visibility timeout must exceed the total processing time to avoid duplicates in SQS-Lambda integrations.
Answer
The correct answer is: C