Measuring cold start time of AWS Lambda functions with Java and SnapStart

Aleksandr Filichkin
5 min readMar 26

I hope everyone already knows that Java is not a perfect language for AWS Lambda because of its huge cold start(first start) issue. You can read about it in my previous article.

What is SnapStart

At AWS re:Invent 2022, AWS announced SnapStart for AWS Lambda running on Java Corretto 11. AWS says that this feature will significantly (10x) reduce the cold start latency and this feature is free, with no additional costs.

SnapStart is a feature that improves the startup time of Lambda functions. When a customer releases a new version of their function, the Lambda service initializes its code and creates an encrypted snapshot of the execution environment. This snapshot is stored in a cache with multiple tiers for quick and easy access.

Later, when the function is called and scaled, Lambda retrieves the execution environment from the stored snapshot instead of starting from scratch. This process significantly reduces the time it takes for the function to start up, resulting in lower latency.

The lifecycle of a Lambda function

As always all code is available on my GitHub https://github.com/Aleksandr-Filichkin/aws-lambda-snapstart. The repo contains all required Terrafrom scripts and has GitLab Actions.

Test scenario

API-Gateway -> AWS Lambda->DynamoDb

We are going to compare the performance of plan Java implementation and Java + SnapStart.

Plain Java (without SnapStart)

  • Java 11
  • AWS SDK-V2 for Dynamodb
  • No DI (Spring, etc)
  • No special frameworks
  • Utilize CPU burst on startup (move everything to static, warm-up dynamo DB client by saving a dummy data into Dymanodb)
  • Reduce dependencies(exclude Netty)
  • Specify AWS Regions
  • Specify Credential Provider
public class BookHandler implements RequestHandler<APIGatewayProxyRequestEvent, APIGatewayProxyResponseEvent> {

/**
* All clients should be static and initialized on init state, it dramatically reduces cold start, because use CPU burst of AWS Lambda.
*/…