DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Related

  • Building Scalable Data Lake Using AWS
  • Building a Scalable ML Pipeline and API in AWS
  • Breaking AWS Lambda: Chaos Engineering for Serverless Devs
  • AWS Step Functions Local: Mocking Services, HTTP Endpoints Limitations

Trending

  • Agile’s Quarter-Century Crisis
  • How to Merge HTML Documents in Java
  • Developers Beware: Slopsquatting and Vibe Coding Can Increase Risk of AI-Powered Attacks
  • Using Python Libraries in Java
  1. DZone
  2. Testing, Deployment, and Maintenance
  3. Deployment
  4. AWS Lambda SnapStart

AWS Lambda SnapStart

AWS Lambda SnapStart is a new feature that was introduced by AWS on Nov 29, 2022 to reduce the cold start times of Lambda.

By 
Kiran Kumar user avatar
Kiran Kumar
·
Jun. 22, 23 · Tutorial
Likes (1)
Comment
Save
Tweet
Share
5.1K Views

Join the DZone community and get the full member experience.

Join For Free

AWS Lambda SnapStart is a new feature that was introduced by AWS on Nov 29, 2022, to reduce the cold start times of Lambda.

Lambda cold start times has been one of the limitations for many years that increases the latency, and this recent change with SnapStart will decrease the latency that minimizes cold starts.

Currently, this feature in Lambda is available on Java 11 and Java 17 runtimes.

Before going deep dive into this, we will see how Lambda execution takes place and the phases of execution

AWS Lambda SnapStart

Lambda execution contains two phases: cold start and warm start.

Overall, the Lambda function is a service running on a virtual machine managed by AWS. For an end user, this is considered serverless.

Cold start can be considered like bootstrapping the system, where this will incur latency in making the system available.

In the cold start, code is downloaded from the specified location like an S3 bucket that the Lambda function executes, creates an execution environment, and executes initialization code (like the init method in the Lambda function that has functionalities related to creating database connections or any other objects).

Once Lambda functions cold start phase is completed, Lambda will be available to handle and process the requests. This phase is called the warm phase. The actual execution of the Lambda function is mainly in the warm phase, and the performance of the Lambda function is determined by the time of execution in the warm phase.

Because of cold starts, Lambda function execution incurs latency in the actual processing of the request.

Scenarios where Lambda cold starts occur:

  1. When the Lambda function is deployed for the first time
  2. Concurrent request processing during Lambda function scaling

Lambda execution environments handle one request at a time. After the invocation of the Lambda function has ended, the execution environment is retained for a period. If another request arrives within the period, the environment is reused to handle the subsequent request. In this scenario, there is no cold start.

If requests arrive simultaneously or concurrently, the Lambda service scales up the Lambda function to provide multiple execution environments. Each environment setup experiences a full cold start.

concurrent requests

In case there is a delay between the requests for each Lambda execution, the existing environments are reused if the previous invocation has been completed. In this scenario, there is no cold start, as well.

  1. If the Lambda function is idle for more than 15 minutes (max time out period) (i.e.) no request is getting processed, the existing container of Lambda is destroyed, and after that, any new request invokes the Lambda function, which will incur a cold start.

Ways To Reduce Cold Starts

  1. Use Lambda Provisioned Concurrency: This feature keeps Lambda functions initialized and warm. Unlike on-demand Lambda functions, this means that all setup activities happen ahead of invocation (including container start, bootstrap runtime, and running the initialization code). Provisioned concurrency adds cost to Lambda service.
  2. Reduce the init code execution time by utilizing some design patterns (for example, connection pool-like libraries).
  3. AWS Lambda SnapStart: New feature introduced recently for Java 11 Corretto runtime. This also will result in Lambda Provisioned Concurrency but with no cost.

How AWS Lambda SnapStart Works

How AWS Lambda SnapStart Works

When the Lambda function with SnapStart enabled is published, this will prepare the execution environment and initialization activity. A snapshot of the execution environment is created, encrypted, and cached for a certain duration

Now when the Lambda function is executed the first time or scaled for concurrent execution, there will not be a cold start, and the snapshot of the execution environment is restored from the cache.

In case of 14 days of inactivity on the Lambda function, the snapshots are removed from the cache.

Activation of AWS Lambda SnapStart

  • Open the functions page of the Lambda console.
  • Choose the name of a function.
  • Choose configuration, and then choose the general configuration.
  • On the general configuration pane, choose edit.
  • On the edit basic settings page, for SnapStart, choose published versions.
  • Choose save.
  • Publish a function version. Lambda initializes your code, creates a snapshot of the initialized execution environment, and then caches the snapshot for low-latency access.
  • Invoke the function version.

Note: AWS Lambda SnapStart will not work for unpublished versions.

Proof of Concept

In this proof of concept, consider a Lambda function with Spring Boot code deployed in the Singapore region with Java 11/17 and Corretto runtime.

In the configuration section, edit SnapStart for published versions:

edit SnapStart for published versions

In the versions section, publish the version.

In the versions section, publish the version

When the version is getting published, SnapStart creates an execution environment, and the snapshot is cached.

Before the first invocation only, the Lambda execution environment is created.

the Lambda execution environment is created

Go to alias, create alias name, and for the alias, create function URL.

In this POC, load testing is done with the Apache bench tool for below two use cases:

Case 1: Execute the unpublished version of Lambda (SnapStart not enabled) with 10 concurrent requests and total of 100 requests. This will incur cold starts:Execute the unpublished version of Lambda


This will incur cold startsCase 2: Execute the published version of Lambda (SnapStart is enabled) with 10 concurrent requests and a total of 100 requests. This will not incur Cold Starts.

Execute the published version of Lambda (SnapStart is enabled) with 10 concurrent requests and total 100 requests

This will not incur Cold Starts

For 100% requests, Lambda with SnapStart has taken 1902 ms.

For 100% of requests, Lambda without SnapStart has taken 6249 ms.

With SnapStart enabled, the latency is reduced to 70%. This proves that SnapStart is reusing the cached snapshot of the execution environment during Lambda invocations which are not leading to cold starts.

Conclusion

AWS Lambda is a powerful, flexible service for building and running serverless applications. With Lambda, you can easily scale your application to handle any workload without worrying about infrastructure or capacity planning.

You can use the AWS Lambda SnapStart to quickly and easily set up a serverless application with everything you need to get up and running in just a few clicks. The SnapStart includes a range of templates and resources that make it easy to build and deploy your application, and you can use the AWS Management Console or the AWS CLI to manage your functions and events.

AWS AWS Lambda End user Virtual Machine

Published at DZone with permission of Kiran Kumar. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Building Scalable Data Lake Using AWS
  • Building a Scalable ML Pipeline and API in AWS
  • Breaking AWS Lambda: Chaos Engineering for Serverless Devs
  • AWS Step Functions Local: Mocking Services, HTTP Endpoints Limitations

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!