Question

Difficulty: EasyMessage-Based Integration using Amazon SQS and SNS

A developer is writing a background worker application that processes messages from an Amazon SQS queue. Each message takes exactly 45 seconds to process. The SQS queue has a default visibility timeout of 30 seconds. Currently, the worker successfully processes the messages, but the same messages keep appearing back in the queue and are processed multiple times, causing duplicate records. Which of the following actions should the developer take to resolve this issue? (Select TWO.)

  1. Increase the visibility timeout of the Amazon SQS queue to a value greater than 45 seconds.Answer
  2. Ensure the worker application calls the SQS DeleteMessage API operation after the message is successfully processed.Answer
  3. C
    Decrease the visibility timeout of the Amazon SQS queue to 15 seconds so that messages can be processed faster.
  4. D
    Embed the AWS Access Key ID and Secret Access Key directly in the worker application's SQS client configuration code to authorize the DeleteMessage operation.
  5. E
    Increase the execution timeout of the consumer AWS Lambda function to 15 minutes while leaving the SQS visibility timeout at 30 seconds.

Answer

To resolve the issue, the developer must increase the SQS queue's visibility timeout to a value greater than 45 seconds (the processing time) and configure the worker to explicitly call the DeleteMessage API after successful processing.
The correct actions are to increase the visibility timeout of the SQS queue to a value greater than the processing time of 45 seconds, and to ensure that the worker application explicitly calls the DeleteMessage API operation after processing. SQS messages are only hidden temporarily during the visibility timeout; if the processing time exceeds this timeout, or if the message is never deleted, the message will become visible again to other consumers, resulting in duplicate processing.

Step-by-Step Solution

1
Identify the relationship between the message processing time and the SQS visibility timeout.
The processing time (45 seconds) exceeds the visibility timeout (30 seconds), causing the message to become visible to other workers while still being processed.
To prevent premature reprocessing, the SQS visibility timeout must be set to a value greater than the maximum expected processing time.
2
Ensure the worker application cleans up successfully processed messages.
The worker application must explicitly delete the message from the queue after processing is complete.
SQS does not automatically delete messages upon retrieval; they must be removed via the DeleteMessage API to prevent them from becoming visible again.

Key Concept

Amazon SQS message visibility timeout and explicit deletion
Rate this question