software.developer
software.developer

Reputation: 298

Retries in aws lambda for External API timeout

I have a aws lambda function which is invoked by API Gateway. The Lambda function calls external API endpoints and it sometime receives network time out while calling external API. What is the best way to implement retry mechanism in aws lambda to handle network time out or other server side errors? Also is it good to use retry inside lambda function, which cost as per execution time? Any recommendation is highly appreciated. Regards

Upvotes: 0

Views: 1367

Answers (2)

nickolay.laptev
nickolay.laptev

Reputation: 2565

What is the best way to implement retry mechanism in aws lambda to handle network time out or other server side errors?

You can throw time out error further and don't handle it in your Lambda function, in this case your Lambda will be invoked again. Please note that it depends on configuration of your Lambda (i.e. number of retries set).
You can find more theory and practical examples here.

Also is it good to use retry inside lambda function, which cost as per execution time?

Lambda Retries are free for you (you pay only for Lambda execution and not for retry logic). Implementing your own retry approach inside Lambda is not free for you, because you pay for its execution.

Upvotes: 1

elbik
elbik

Reputation: 1897

  1. You may increase the lambda execution time limiting.

  2. You may track the execution time of the lambda, and when it close to limit, re-call your lambda with the same payload. I mean that lambda re-triggers itself until the external API would successfully response.

  3. You can introduce SQS(Simple Queue System) to your system, where the messages for external API will be stored. And the some of consumer will send messages to external API. It may be an another lambda or some another running service which is responsible just for calling external API.

Upvotes: 0

Related Questions