Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What happens when an AWS Lambda times out?

I understand that when a Lambda times-out, it returns an error.

Once the Lambda times-out, though, I'd like to know if it's immediately killed by AWS, or if it can potentially continue running for an arbitrary amount of time in the background (detached from the original request, so to speak).

I ask because it's important in my situation that when a Lambda times out, all processing inside that Lambda also stops immediately. If AWS does not guarantee this, then I will need to implement my own measures to ensure this for myself, i.e. by periodically checking against the clock and manually halting execution beyond the timeout.


(p.s. if Lambdas are killed immediately on timeout, I'd like to know how AWS achieves keeping the Lambda in a warm, initialised state for subsequent invocations. I.e. it cannot simply be that it kills the process on timeout, otherwise the Lambda would be cold for next time...)

like image 531
Lawrence Wagerfield Avatar asked Oct 15 '25 18:10

Lawrence Wagerfield


1 Answers

The execution of the lambda function will stop, but not necessarily the execution of external processes that have been called from lambda, such as external API or other AWS services.

To avoid issues, AWS lambda has a context method getRemainingTimeInMillis(), allowing you to check during execution how much time is left before the timeout. https://docs.aws.amazon.com/lambda/latest/dg/nodejs-context.html

From my own experience, most of the time the lambda stays warm. AWS killed the execution of the code, not the instance.

like image 173
Jeremie Avatar answered Oct 18 '25 08:10

Jeremie



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!