Skip to content

Enable Lambda SnapStart ​

Lambda SnapStart reduces cold start times. AWS initializes your function once per deploy, takes a snapshot of it, and resumes from that snapshot on a cold start instead of initializing again.

SnapStart is available for apps that use the Lambda Service (Container) module (nullstone/aws-lambda-container-service), version 0.11.0 or later. It is off by default.

Before you start ​

Your image must opt in ​

AWS only snapshots images that declare support for it.

  • AWS base images for Java 11+, Python 3.12+, and .NET 8+ work as-is.

  • Any other image must add this label to its Dockerfile:

    dockerfile
    LABEL com.amazonaws.lambda.feature.snapstart="Allow"

    Alternatively, the image can implement the restore runtime API.

Build and deploy an image that opts in before you enable SnapStart. If the running image has not opted in, the change that enables SnapStart fails.

Initialization runs once per deploy ​

With SnapStart, your initialization code runs when the app is deployed, not on each cold start. Every execution environment restored from the snapshot starts with the same memory.

Create anything unique or short-lived in the handler, or in an after-restore hook, rather than during initialization:

  • Random seeds and generated IDs
  • Network connections, such as database connections
  • Temporary credentials and cached tokens

Initialization, including any before-snapshot hooks, must finish within the function timeout or 130 seconds, whichever is longer.

Not supported with SnapStart ​

  • Provisioned concurrency
  • Amazon EFS
  • More than 512 MB of ephemeral storage

Enable SnapStart ​

Set the snapstart variable on the app and apply the change.

In the Nullstone UI, go to the app's Configuration tab, set snapstart, and apply changes.

With IaC files, add it to the app's vars:

yaml
apps:
  api:
    module: nullstone/aws-lambda-container-service
    vars:
      snapstart:
        enabled: true
SettingDefaultDescription
enabledfalseTurns SnapStart on.
versions_to_keep3How many published versions to keep, including the one receiving traffic. Must be at least 1.

Plan for a brief interruption

Turning SnapStart on or off re-points every trigger and ingress, which briefly interrupts them. Make the change during a quiet period.

If the app uses the aws-lambda-api-gateway capability, the API is recreated during that apply. The URL stays the same, but requests fail until the apply finishes.

What changes ​

Traffic goes through an alias ​

SnapStart only applies to published versions of a function, so Nullstone creates an alias named live and points every trigger and ingress at it.

Deploys take longer ​

Each deploy now does the following:

  1. Updates the function's environment variables and image.
  2. Publishes a new version of the function.
  3. Waits for AWS to initialize and snapshot that version.
  4. Moves the live alias to the new version. This is the moment the deploy takes effect.
  5. Removes old versions, keeping the newest versions_to_keep.

If AWS cannot prepare the new version, for example because initialization fails, the deploy fails and the alias stays on the previous version.

Cost ​

AWS charges for each stored snapshot and for each restore. See Lambda pricing. Every kept version has a stored snapshot, so a lower versions_to_keep costs less.

Turn SnapStart off ​

Set enabled to false and apply. Triggers and ingress return to invoking the function directly.

Versions published while SnapStart was on are not removed automatically. Delete them in the AWS console if you no longer need them.