17

From https://docs.aws.amazon.com/lambda/latest/dg/with-sqs.html#events-sqs-queueconfig

Set your queue visibility timeout to 6 times your function timeout, plus the value of MaximumBatchingWindowInSeconds

Why can't the queue visibility timeout be equal to the function timeout? Let's say the function has a timeout of 30 seconds, so is the queue visibility. The function picks up the message and 30s passed, the message has not been deleted, now it's visible for other functions/consumers. Then why does it have to be 6 times? And what role does maxium batching window plays in queue visiblity timeout?

Steve Chambers
  • 37,270
  • 24
  • 156
  • 208
psyud
  • 315
  • 2
  • 7

1 Answers1

7

Then why does it have to be 6 times?

The explanation is given in the next sentence:

The extra time allows for Lambda to retry if your function execution is throttled while your function is processing a previous batch.

This is just a recommendation. You don't have to follow.

Marcin
  • 215,873
  • 14
  • 235
  • 294
  • I know it's for the extra time. Why does the extra time have to be that much? – psyud Dec 17 '20 at 03:52
  • I know I don't have to follow it right? Just wondering the reason behind their recommendations. – psyud Dec 17 '20 at 03:53
  • 1
    @psyud I don't there is any math formula for that. Its something AWS considers as a "rule of thump". In SQS batch you can get 10 messages at once, which usually are processed in a loop in lambda. If one msg takes 10 seconds to process, the last one will have to wait 100 seconds. Add to this some retry time when lambda fails and you may end up with much greater visibility time then lambda execution time. – Marcin Dec 17 '20 at 04:02