I have SQS as an event source for Lambda. My Lambda function gave an error while processing the record from SQS before the visibility timeout expired. My doubt is will the Lambda instantly retry the failed record? Or the failed record will only be retried once it becomes visible again in the queue after the timeout expires? If the lambda will retry instantly how many number of times will it retry?
Well, you asked three different questions, and here are my answers:
1. My doubt is will the lambda instantly retry the failed record?
No, but if your Lambda processing time is equal to the message visibility timeout value, then it looks like the failed message is retried immediately.
2. Or the failed record will only be retried once it becomes visible again in the queue after the timeout expires?
Yes, but it's not only for the failed record because SQS doesn't know anything about lambda failures. In fact, if Lambda takes more time to process the SQS message than the configured visibility timeout, even then SQS will resend the same message to the consumer for processing. So, if the consumer fails to remove the message from SQS within the visibility timeout value, the same message will be resent to the consumer.
3. If the lambda will retry instantly how many number of times will it retry?
It depends on the "message retention period". The message will be automatically removed from the queue after the retention period. So, as long as the message is available in the queue, it will be visible to the consumer for processing. But, you can control the message retry functionality by introducing the dead-letter queue.