Lambda Retry on a specific Error Code

0

There's a Lambda function which calls other external service. If the service returns us 429 error code, Then the Lambda needs to retry the call until we get success, for a max of three times, with 10,20,30 minutes Gap.

The issue is Lambda can run only upto 15min's Max. So using timeout is not Possible.

How can this usecase be tackled? Thanks in Advance

kishore
asked 10 months ago788 views
2 Answers
2

Hello! Step Functions would be the ideal implementation. However maybe it can be an overkill if your implementation is very simple or if you want a quick solution.

For example, if you are using an SQS Queue to trigger the Lambda, a quick implementation could be to delete the message from the queue and re-publish it using what is called a "MessageTimer" with a DelaySeconds (more info here) property set to 10, 20, 30 minutes respectively (NOTE: minutes have to be specified in seconds within this property). Then, the queue will "hide" this message from publication until the specified delay has passed accomplishing the "retry" mechanism you are expecting.

Hope this helps!

PS: From the Amazon SQS documentation available here: "To set delay seconds on individual messages, rather than on an entire queue, use message timers to allow Amazon SQS to use the message timer's DelaySeconds value instead of the delay queue's DelaySeconds value."

profile pictureAWS
answered 10 months ago
  • @kishore did my answer help?

0

Hi,

AWS Step Functions is a great service for use-cases like yours that involve orchestration. With Step Functions you can create a simple state machine that calls your AWS Lambda function. Step Functions has built-in retry and error handling, so you can configure the number of retries as well as the interval between them. For more information, please check: https://docs.aws.amazon.com/step-functions/latest/dg/concepts-error-handling.html

Please upvote/accept this answer if it was helpful.

profile pictureAWS
EXPERT
answered 10 months ago
profile picture
EXPERT
reviewed 10 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions