What's Happening when an AWS Lambda Function Freezes

2.3k Views Asked by At

What's going on behind the scenes when an AWS lambda function freezes?

That is -- many of the Lambda Runtime Docs refer broadly to the concept of a function freezing or unfreezing

The runtime and each extension indicate completion by sending a Next API request. Lambda freezes the execution environment when the runtime and each extension have completed and there are no pending events.

My understanding of this is that after a Lambda function initializes (or "cold starts") and executes the first invocation request, if there are no other invocations to process the function's execution environment will "freeze". Then, when there's another function invocation to process, the function's execution environment will "unfreeze" almost instantly without needing to initialize/cold-start again. If a frozen function goes too long without being invoked it will shutdown, and the next invocation request will need to cold start.

Does anyone know what this freezing is? It's my understanding that these execution environments are firecracker virtual machines. Is this freezing something that firecracker supports, or is it some extra magic that AWS Web Services has that they keep to themselves? Put another way, if I have a Firecracker VM running can I freeze and unfreeze it?

1

There are 1 best solutions below

1
On

We can understand the freeze as after each execution, AWS Lambda putting the instance to sleep. In other words, the instance freezes (similar to a laptop in hibernate mode). The virtual CPU is turned off. This frees up resources on the worker node. The overhead from waking up such a function is negligible.

For understand how Firecracker works under the hood, take a look on this AWS re:Invent of 2019 video: AWS re:Invent 2019: Firecracker open-source innovation (OPN402)

Also, take a look on this posts: