0

I have a lambda function that pulls data from the event stream from DynamoDB. Inside the lambda function, I have a REST call to one of the internal API endpoint. The current timeout set for Lambda is 60 seconds.

Problem: In logs I am noticing that once in a while Lambda throws a timeout exception. It might be because my API did not process the request within 60 seconds.

Question: I want to understand in case lambda times out then what happens to events and calls that are being sent to the internal API/ REST Calls. Will those calls/events will be retried and sent again to the API out of the box?

I read below links:

https://docs.aws.amazon.com/lambda/latest/dg/invocation-eventsourcemapping.html

AWS Lambda processing stream from DynamoDB

but I am not able to comprehend whether the API will receive those events/calls again.

halfer
  • 19,824
  • 17
  • 99
  • 186
Unbreakable
  • 7,776
  • 24
  • 90
  • 171
  • No, lambda retries no such calls, why would it / how could it? When the lambda times out its execution is terminated, the outgoing network request is cancelled / aborted / simply does not continue, whether or not the target server received or continues to execute the request is no longer your concern. If your lambda invocation is retried then what happens is once again entirely up to you: do you send another request or not, your code, your decision. Lambda does not know or care about some API calls you perform from within your code. – luk2302 Mar 08 '22 at 12:44
  • https://docs.aws.amazon.com/lambda/latest/dg/invocation-eventsourcemapping.html – Unbreakable Mar 08 '22 at 12:47
  • https://stackoverflow.com/questions/51956472/aws-lambda-processing-stream-from-dynamodb – Unbreakable Mar 08 '22 at 12:48
  • https://blog.rowanudell.com/understand-your-lambda-event-retries/ – Unbreakable Mar 08 '22 at 12:48
  • https://dashbird.io/blog/aws-lambda-error-handling-step-functions/ – Unbreakable Mar 08 '22 at 12:48
  • https://hackernoon.com/simple-steps-to-avoid-the-retry-behavior-from-aws-lambda-su4w63yx9 – Unbreakable Mar 08 '22 at 12:48
  • Yes, bunch of links...!? – luk2302 Mar 08 '22 at 12:48
  • @luk2302 - When I read them, it says that lambda will retry if there is timeouts during *Event based invication*. I am a newbie so I don't know the working of lambda properly. So was asking for more clarity. Thanks! – Unbreakable Mar 08 '22 at 12:49
  • The lambda invocation may be retried yes. Then your code runs again and you can do whatever you want. If you decide to call the api again then you call the api again, Lambda does not care. – luk2302 Mar 08 '22 at 12:50
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/242724/discussion-between-unbreakable-and-luk2302). – Unbreakable Mar 08 '22 at 12:51

1 Answers1

2

For context, this question is about DynamoDB Streams and AWS Lambda triggers. Specifically, how the AWS Lambda service handles failed or timed out event handling by Lambda functions that were invoked by the Lambda service to handle events in DynamoDB Streams.

Per the Using AWS Lambda with Amazon DynamoDB documentation:

If your [Lambda] function returns an error, Lambda retries the batch [of DynamoDB Streams events] until processing succeeds or the data expires.

Lambda treats all other results [anything but complete success] as a complete failure and retries processing the batch up to the retry limit.

So, I would infer that a timeout is not a complete success and hence the entire batch is retried.

By the way, you mentioned "I have a lambda function that pulls data from the event stream from DynamoDB" but this is not actually how the DynamoDB Streams / Lambda integration works. The Lambda service polls the DynamoDB Stream and then invokes your Lambda function, pushing the DynamoDB data to you.

jarmod
  • 71,565
  • 16
  • 115
  • 122
  • Does a timeout is considered as "error" which gets retried? – Unbreakable Mar 08 '22 at 14:01
  • I updated my answer in advance of your comment. I haven't tested this, but I would assume that a timeout is not a complete success and hence the batch will be retried. It wouldn't make much sense otherwise, imo. You should be able to verify this with a quick test, hopefully. – jarmod Mar 08 '22 at 14:02