Search code examples
node.jsamazon-web-servicesaws-lambdaamazon-sqsserverless

Will Lambda receive SQS messages that have been consumed?


I have a system design like this

SQS -> trigger -> Lambda -> if fails -> DLQ

pre condition

  1. Lambda function using a try catch block , it won't throw any errors .
  2. Lambda function never run out of memory , or timeout . (from Lambda monitoring)
  3. Error count is 0 in Lambda monitoring
  4. Never use SQS console to view messages
  5. Lambda SQS batchSize set to 1
  6. DLQ Maximum Receives set to 1
  7. Lambda invocation about 60k

After running for a while

  1. we found a few message in DLQ
  2. message in DLQ has attributes ApproximateReceiveCount is 2 or bigger.

Is this as expected ?

In my opinion if no error throws in Lambda , DLQ message should always be zero .


Solution

  • SQS is designed to provide at least once delivery. There is a chance that your message could be received by more than one lambda invocation.

    If you need exactly once delivery, consider using a fifo queue.

    Regarding the second part of your question - why are messages being written to the DLQ. The easiest way to troubleshoot that is to look for the lambda invocation logs which match some uniquely identifying aspect of the SQS message in the DLQ.