Search code examples
amazon-web-servicesqueueamazon-sqs

SQS Message Processing


I created a standard queue with the following specs:

  1. delay seconds: 0
  2. max receive count (redrive policy): 10
  3. visibility timeout: 300

I have a lambda consumer that receives the messages. From the documentation, it says that you need to explicitly delete the message in the consumer once it is processed (at least to guarantee that it is removed). However, it seems that the messages get deleted on their own regardless of them being deleted in the consumer or if the consumer returns an unsuccessful status code. The only way I've seen a message return to the queue is when I raise some sort of runtime error in the consumer.

Question: What is a proper error message to return to the consumer so that it knows to not delete the message?


Solution

  • The Lambda service communicates with the queue, applying success and failure conditions to your function's return value. In a nutshell, the Lambda service interprets:

    • Null or empty responses from your Lambda as 100% batch success
    • Thrown errors or malformed responses as 100% batch failure
    • Valid batchItemFailures in the response as partial failures

    You can optionally manually delete messages from the queue with a DeleteMessage SDK call, although there is no obligation to do so. Manual deletion might make sense if your service is not idempotent and you really need to avoid double-processing.