Blogger news

Blogger templates

Thursday, November 2, 2017

Container model execution of AWS Lambda

When AWS Lambda executes your Lambda function on your behalf, it takes care of provisioning and managing resources needed to run your Lambda function. When you create a Lambda function, you specify configuration information, such as the amount of memory and maximum execution time that you want to allow for your Lambda function. When a Lambda function is invoked, AWS Lambda launches a container based on the configuration settings you provided. Container creation and deletion are completely handling by AWS and there is no way a user can manage it. 

You can expect a delay when Lambda is invoked the first time or if there is a delay between subsequent requests because it takes time to set up the container and does other setups. AWS Lambda tries to reuse the container for subsequent invocations of the Lambda function.   

After a Lambda function is executed, AWS Lambda maintains the container for some time. It means the service freeze the container for some time after a function execution completes and in that period if an invocation happens then Lambda will reuse the previous container. 

The container reuse has few implications, 

  • Any declarations in your Lambda function code outside the handler code remains initialized. For example, if your Lambda function establishes a dynamoDB connection in the first run then instead of re-establishing the connection, the original connection is used in subsequent invocations.

  • Background processes or callbacks initiated by your Lambda function that did not complete when the function ended resume if AWS Lambda chooses to reuse the container. You should make sure any background processes or callbacks in your code are complete before the code exits.
When you write your Lambda function code, do not assume that AWS Lambda always reuses the container because AWS Lambda may choose not to reuse the container. Depending on various other factors, AWS Lambda may simply create a new container instead of being reusing an existing container.

No comments:

Post a Comment