feat: add Lambda SnapStart support#790
Merged
Merged
Conversation
bnusunny
force-pushed
the
snapstart-support
branch
from
July 9, 2026 16:17
b28a336 to
9fa790d
Compare
Switch from the git-branch dependency to the published lambda_http/lambda_runtime 1.3.0 from crates.io, removing the release blocker. Also fix the integration test body-reader helpers to accept the BoxBody response type, and resolve a clippy ok().expect() lint.
bnusunny
force-pushed
the
snapstart-support
branch
from
July 9, 2026 16:21
9fa790d to
ada9aa2
Compare
licjun
reviewed
Jul 9, 2026
| @@ -0,0 +1,65 @@ | |||
| import os | |||
licjun
approved these changes
Jul 9, 2026
This was referenced Jul 9, 2026
Merged
bnusunny
added a commit
that referenced
this pull request
Jul 10, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds AWS Lambda SnapStart support to the Lambda Web Adapter. Because the adapter runs the customer's web application as a separate process with no access to the Lambda Runtime API, the application cannot participate in the SnapStart lifecycle on its own. This PR makes the adapter a SnapStart bridge: it registers the runtime's
SnapStartResourcehooks and relays the before-checkpoint and after-restore lifecycle events to the inner application over HTTP.What it does
Two opt-in, independent environment variables:
AWS_LWA_SNAPSTART_BEFORE_CHECKPOINT_PATHAWS_LWA_SNAPSTART_AFTER_RESTORE_PATHafter_restore()performs three ordered steps (before any invocation is served):OnceLock) so it never reuses a connection captured in the snapshot — this happens first so the hook call itself uses a fresh connection.Each hook POST is bounded by a 60s timeout; the post-restore readiness check is bounded by a tighter 10s timeout. A non-2xx, connection error, or timeout at any step fails the SnapStart phase (
/init/errorfor before-checkpoint,/restore/errorfor after-restore) rather than serving traffic against an improperly restored app.Security: the hook routes live on the app's HTTP surface, so external requests (via API Gateway/ALB) targeting a configured hook path receive
403 Forbiddenand are never forwarded to the app.Behavior is unchanged when SnapStart is not in use — the runtime lifecycle is a no-op, and the hooks are unset by default. The previous
pool_max_idle_per_host(0)SnapStart special-case is removed in favor of the at-restore client swap, which restores connection pooling for steady-state throughput.Notable implementation details
lambda_http/lambda_runtime1.3.0 (adds theSnapStartResourceAPI).fetch_responsereturn type changed toResponse<BoxBody<Bytes, Error>>so the synthetic 403 can share the return type with proxied responses.readiness.rs, reused by both the adapter and the after-restore step.Testing
connection_id; the failure path (unready app) times out the readiness check at ~10s and fails the restore withSnapStartTimeoutException.cargo test,cargo clippy --all-targets -- -Dwarnings, andcargo fmt --checkall pass.Examples
Two deployable examples:
examples/fastapi-snapstart(container image / OCI) andexamples/fastapi-snapstart-zip(managed runtime layer), each demonstrating connection drain/reconnect across a restore.