SQS Lambda Integration - what happens when an Exception is thrown

Viewed 2586

The document states that

A Lambda function can fail for any of the following reasons:

The function times out while trying to reach an endpoint.

The function fails to successfully parse input data.

The function experiences resource constraints, such as out-of-memory errors or other timeouts.

For my case, I'm using C# Lambda with SQS integration

If the invocation fails or times out, every message in the batch will be returned to the queue, and each will be available for processing once the Visibility Timeout period expires

My question: What happen if I, using an SQS Lambda integration ( .NET )

  • My function throws an Exception
  • My SQS visibility timer is set to 15 minutes, max receive count is 1, DLQ setup

Will the function retry? Will it be put into the DLQ when Exceptions are thrown after all retries?

1 Answers

The moment your code throws an unhandled/uncaught exception Lambda fails. If you have max receive count set to 1 the message will be sent to the DLQ after the first failure, it will not be retried. If your max receive count is set to 5 for example, the moment the Lambda function fails, the message will be returned to the queue after the visibility timeout has expired.

The reason for this behaviour is you are giving Lambda permissions to poll the queue on your behalf. If it gets a message it invokes a function and gives you a single opportunity to process that message. If you fail the message returns to the queue and Lambda continues polling the queue on your behalf, it does not care if the next message is the same as the failed message or a brand new message.

Here is a great blog post which helped me understand how these triggers work.

Related