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.

Freedom Month Sale — Discounts That Set You Free!

  • Up to 80% OFF AWS Courses
  • Up to 30% OFF Microsoft Certs
Act Fast!

About CloudThat

CloudThat is an award-winning company and the first in India to offer cloud training and consulting services worldwide. As a Microsoft Solutions Partner, AWS Advanced Tier Training Partner, and Google Cloud Platform Partner, CloudThat has empowered over 850,000 professionals through 600+ cloud certifications winning global recognition for its training excellence including 20 MCT Trainers in Microsoft’s Global Top 100 and an impressive 12 awards in the last 8 years. CloudThat specializes in Cloud Migration, Data Platforms, DevOps, IoT, and cutting-edge technologies like Gen AI & AI/ML. It has delivered over 500 consulting projects for 250+ organizations in 30+ countries as it continues to empower professionals and enterprises to thrive in the digital-first world.

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 is a Research Associate with expertise in DevOps and Cloud Infrastructure. He specializes in architecting and automating scalable, secure systems using AWS, Jenkins, Git, Terraform, Ansible, Docker, and Kubernetes. Skilled in Infrastructure as Code (IaC) and CI/CD pipelines, Zubair ensures reliable application delivery and efficient operations. He also sets up monitoring stacks with Prometheus and Grafana to maintain system performance. Driven by curiosity and continuous learning, he actively contributes to implementing modern DevOps practices aligned with organizational goals.

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!