
Ultimate access to all questions.
Deep dive into the quiz with AI chat providers.
We prepare a focused prompt with your quiz and certificate details so each AI can offer a more tailored, in-depth explanation.
An image-processing company has a web application that users use to upload images. The application uploads the images into an Amazon S3 bucket. The company has set up S3 event notifications to publish the object creation events to an Amazon Simple Queue Service (Amazon SQS) standard queue. The SQS queue serves as the event source for an AWS Lambda function that processes the images and sends the results to users through email.
Users report that they are receiving multiple email messages for every uploaded image. A solutions architect determines that SQS messages are invoking the Lambda function more than once, resulting in multiple email messages.
What should the solutions architect do to resolve this issue with the LEAST operational overhead?
A
Set up long polling in the SQS queue by increasing the ReceiveMessage wait time to 30 seconds.
B
Change the SQS standard queue to an SQS FIFO queue. Use the message deduplication ID to discard duplicate messages.
C
Increase the visibility timeout in the SQS queue to a value that is greater than the total of the function timeout and the batch window timeout.
D
Modify the Lambda function to delete each message from the SQS queue immediately after the message is read before processing.
Explanation:
This issue occurs because SQS standard queues provide at-least-once delivery, which means messages can be delivered more than once. When a Lambda function processes messages from an SQS queue, it automatically deletes messages from the queue after successful processing. However, if the Lambda function fails or times out before completing processing, the message becomes visible again in the queue and can be reprocessed.
Key Concepts:
Visibility Timeout: When a consumer receives a message from SQS, the message becomes invisible to other consumers for a period called the visibility timeout. If the message isn't deleted within this timeout period, it becomes visible again and can be processed by another consumer.
Lambda Event Source Mapping: When Lambda is configured with SQS as an event source, it automatically:
Why Option C is Correct:
Increasing the visibility timeout to a value greater than the total of the function timeout and batch window timeout ensures that:
Why Other Options Are Not Optimal:
Best Practice: The recommended approach is to ensure the visibility timeout is at least 6 times the Lambda function timeout to account for retries and processing delays. This ensures messages aren't reprocessed while the function is still running or retrying.