AWS, Cloud Computing

5 Mins Read

AWS re:Invent 2022 : Introducing AWS Lambda SnapStart

Voiced by Amazon Polly

Introduction

AWS Lambda is a popular serverless computing platform that allows developers to run code without worrying about infrastructure management. However, one issue with serverless computing is the “cold start” problem, where the first execution of a function after it has been idle for a period of time can take longer than subsequent executions. This can be a problem for applications requiring low latency or strict performance requirements.

To help mitigate the cold start problem, AWS recently introduced a new feature called “SnapStart” for Lambda functions. This blog will look closely at SnapStart and how it can help reduce the cold start problem.

Pioneers in Cloud Consulting & Migration Services

  • Reduced infrastructural costs
  • Accelerated application deployment
Get Started

What is SnapStart?

  • SnapStart is a feature that enables AWS Lambda to pre-warm function instances by keeping them active and ready to respond to incoming requests.
  • SnapStar can improve the performance of latency sensitive applications by up to 10% without extra cost.
  • Snap Start allows Lambda to keep a pool of warm function instances that can handle requests immediately without any delay.
  • When a function is invoked, Lambda checks if any pre-warmed instances are available in the pool. If there are, it uses one of them to handle the request. If no pre-warmed instances are available, Lambda creates a new instance and adds it to the pool for future requests. This helps to reduce the cold start time by ensuring that warm instances are always available to handle requests.

How Does SnapStar Works?

  • Lambda takes a snapshot of the initialized function’s memory and disk state, encrypts the snapshot, and keeps it as a cache for low-latency access.
  • So, whenever we invoke the function version for the first time, the new invocation scales up, and lambda uses the cached snapshot for execution instead of creating the execution environment from scratch, as it reduces the latency.
  • SnapStart also uses a new feature called “start-up tracing”. Start-up tracing allows Lambda to capture detailed performance metrics during the initialization phase of a function. These metrics optimize the warm-up process and ensure that the pre-warmed instances are always ready to respond to requests.

Benefits of SnapStar

  • Reduced cold start time: By keeping a pool of pre-warmed function instances by creating a snapshot, SnapStart can significantly reduce the cold start time for Lambda functions.
  • Improved performance: SnapStart can help improve the performance of applications that require low latency or have strict performance requirements.
  • Cost savings: By reducing the cold start time and improving performance, SnapStart can help reduce the number of function instances needed to handle requests, leading to cost savings.
  • Simplified management: SnapStart simplifies the management of Lambda functions by automating the warm-up process and ensuring that pre-warmed instances are always available to handle requests.

Step-by-Step Guide to Enable lambda SnapStar

  • Navigate to AWS Lambda from the AWS Management Console.
  • Click on the create function button to create a Lambda Function.

step2

  • Select Author from Scratch under Basic information to provide any function name, and in Runtime, select Java11(corretto) and architecture as To create our lambda function, click the Create Function button.

step3

step3b

  • We are using a default Java function that gives hello world as output after the execution of a function.

step4

  • After our lambda function is created, we will test it by invoking our lambda function.

step5

step5b

  • Under the details, as we can see, the output is Hello from lambda, and the duration time to execute the function is 39.37 ms.
  • Now to enable the SnapStar feature, we need to select the Configuration under that, we have General Configuration. We need to click on the Edit option.

step6

  • In Basic Settings, we have a Description, where we can describe the modifications we have done in the configuration (optional).
  • The Memory (MB) parameter controls how much memory will be available to your Lambda function when invoked. The CPU power allotment likewise increases as memory is increased. A value between 128 and 10240 MB can be chosen (10 GB).
  • Ephemeral Storage allots 512 MB for the /tmp directory of a function. The Ephemeral storage (MB) parameter allows us to change this quantity. In 1-MB increments, we can set a value between 512 MB and 10,240 (10 GB) MB to specify the size of a function’s /tmp directory.
  • SnapStart A performance improvement called Lambda SnapStart helps reduce starting latency without adding extra costs.
  • SnapStart for published versions can be activated on supported runtimes.
  • When you publish a function version, Lambda creates an encrypted snapshot for low-latency access and takes a snapshot of the memory and disc state of the initialized execution environment.
  • Lambda restarts the initialized snapshot and then calls the function handler when you call the function version for the first time and as the number of calls increases.

step7

  • We can keep the default 512 MB as Memory and Ephemeral Storage.
  • In SnapStart, we need to select Published Versions.

step8

  • In the Execution role, select an existing role and click on save.
  • Now go to the Test tab, provide an event name, select private in the Event sharing Settings, and then click Test.

step9

  • After the test execution status is succeeded, click Details to see the logs.

step10

  • We can see the output as Hello from lambda, and the execution duration of the lambda function (i.e., 22 ms) is quite less compared to before enabling the SnapStar feature.

step11

  • By having Lambda cache a snapshot of your function after the function has initialized, SnapStar typically reduces startup time.

Conclusion

SnapStart is a powerful new feature that can help reduce the cold start time for AWS Lambda functions. By using provisioned concurrency and start-up tracing, SnapStart can keep a pool of pre-warmed function instances ready to respond to incoming requests, improving the performance of serverless applications. If you’re using AWS Lambda, take advantage of this powerful new feature to help optimize your serverless applications.

Get your new hires billable within 1-60 days. Experience our Capability Development Framework today.

  • Cloud Training
  • Customized Training
  • Experiential Learning
Read More

About CloudThat

CloudThat is also the official AWS (Amazon Web Services) Advanced Consulting Partner and Training partner and Microsoft gold partner, helping people develop knowledge of the cloud and help their businesses aim for higher goals using best in industry cloud computing practices and expertise. We are on a mission to build a robust cloud computing ecosystem by disseminating knowledge on technological intricacies within the cloud space. Our blogs, webinars, case studies, and white papers enable all the stakeholders in the cloud computing sphere.

Drop a query if you have any questions regarding AWS Lambda SnapStart and I will get back to you quickly.

To get started, go through our Consultancy page and Managed Services Package that is CloudThat’s offerings.

FAQs

1. Which runtimes is Lambda SnapStart compatible with?

ANS: – Lambda SnapStart supports the Java 11 runtime. After they are released, new versions of Java will be supported. See the Lambda runtimes documentation for a list of all runtimes it supports.

2. Can I configure Lambda SnapStart on both x86 and Arm architectures?

ANS: – No, Lambda SnapStart can only be configured for functions executing on the x86 architecture.

3. Will I be charged for Lambda SnapStart?

ANS: – No, Enabling Lambda SnapStart does not incur any further costs. According to the current Lambda Pricing, you are billed based on the quantity of requests for your functions and the length of time your code runs. Runtime hooks, initialization code, declared outside the handler, code executed in a function’s handler, and duration charges apply. Please be aware that AWS Lambda might restart your initialization code and periodically recycle execution environments with security patches.

WRITTEN BY Mohammad Zubair Saifi

Mohammad Zubair Saifi works as a Research Associate at CloudThat. He has knowledge of AWS Cloud Services and resources and DevOps tools like Jenkins, Docker, K8s, Ansible, and Terraform. He is passionate about improving his skills and learning new tools and technologies.

Share

Comments

    Click to Comment

Get The Most Out Of Us

Our support doesn't end here. We have monthly newsletters, study guides, practice questions, and more to assist you in upgrading your cloud career. Subscribe to get them all!