amazon-web-servicesaws-lambdaamazon-sqsaws-sqs-fifo

SQS FIFO queue, and lambda triggered


I have a FIFO SQS, and lambda triggered from that SQS, bulk size on lambda trigger is set to 1, lambda reserved concurrency is set to 1. and SQS visibility timeout is set to 2 minutes as the max amount of time for the lambda processed.

When 2 messages are sent to queue, 1 after the other, Lambda is triggered with 1 message, but the second message is delayed until the visibility timeout passed - 2 minuts. When new messages were sent to queue meanwhile, they were handled immediately.

The behavior I wish to achieve , is that when the lambda finished to handle the first message, a new lambda instance will handle the second message.

I tried changing the visibility timeout to 0, but as the lambda takes longer to execute, it handled the same message over and over.


Solution

  • I understand the behavior, This happened because the message had separate message group id. and reserved concurrency = 1; When message was handled, and finished before the visibility timeout, only messages with same message group id could be handled immediately. Messages with different message group id had to wait for the visibility timeout to pass. I solved it by using constant message group id.