Source: Elena van Engelen-Maslova, aws-lambda-response-streaming-jvm (GitHub, MIT; Maven Central nl.vintik:aws-lambda-streaming-core 3.1.0 and aws-lambda-streaming-sse), with a companion Medium article, announced 23 Nov 2026.
The problem
AWS ships response-streaming helpers for the managed Node.js Lambda runtime only. On the managed Java runtime, the OutputStream a RequestStreamHandler receives is an in-memory buffer that is posted only after the handler returns, so calling flush does nothing. The README measures this: 15 MB written at 2 ms, handler idle for 10 s, first byte at API Gateway at about 10,069 ms. For LLM token streaming that means the user waits for the whole answer.
AWS's documented options are a custom runtime (you own runtime updates) or the Lambda Web Adapter (an HTTP server inside the function). Both give up something: managed patching, SnapStart, CRaC priming, or simplicity.
How the library works
Core module (stable). Implements API Gateway's streaming wire format: a metadata JSON (status, headers), an 8-null-byte delimiter, then body bytes, copied through a fixed 1 MB buffer with per-chunk flush so memory stays flat. This lifts the 6 MB buffered response limit to Lambda's 200 MB streaming limit. One dependency (kotlinx-serialization-json), no AWS SDK artifacts.
SSE module (experimental). Posts the response itself as a chunked request to the Lambda Runtime API, so bytes leave while the handler is still running. A Java agent (your own fat jar with a Premain-Class manifest entry) stops the managed runtime's invocation loop from sending a second response. Packaging must be a zip with the jar under lib/ so the -javaagent path exists.
Result. Against Bedrock Nova Lite via API Gateway, the first token arrives at about 3% of total response time (0.4 s to first token, then 4.7 s of steady tokens in the recorded demo).
Tradeoffs
| Option | Keeps managed runtime and SnapStart | Token streaming | Cost |
|---|---|---|---|
| Buffered RequestStreamHandler | Yes | No | Users wait for the full answer |
| Custom runtime | No | Yes | You own runtime patching |
| Lambda Web Adapter | Partly | Yes | Embedded HTTP server and a layer |
| This library, core | Yes | No (large bodies only) | Small dependency |
| This library, SSE | Yes | Yes | Relies on undocumented runtime internals via a Java agent |
Limits and failure modes
Undocumented internals. The SSE path depends on how the managed runtime's invocation loop behaves today; an AWS runtime update could break it. Pin runtime versions and keep a buffered fallback.
API Gateway REST only. Function URLs aren't supported on the managed JVM runtime with this method.
Throughput cap. After the first 6 MB, Lambda throttles streamed data to 2 MB/s.
Billing after disconnect. The function keeps running and billing until it finishes or times out, even if the client has gone; check for cancellation or cap generation length.
Packaging mistakes. A bare jar as CodeUri is extracted loose, leaving no jar for -javaagent; the zip layout is required.
Padding doesn't help. Adding SSE comment lines to force flushes (a trick used with the Web Adapter in Python) only makes the buffered response bigger here.
Review checklist
Is the SSE module behind a flag, with the buffered path as fallback if the agent fails to attach?
Is the Lambda runtime version pinned and covered by a streaming smoke test in CI?
Does the handler stop generation (or bound max tokens) when the client disconnects?
Is the API exposed through API Gateway REST with RESPONSE_STREAM, not a Function URL?
Does the deployment package put the fat jar under lib/ in a zip, with Premain-Class set?
Is time-to-first-token measured end to end, not just inside the function?
Related entries
R096 NVIDIA Snapshot: checkpoint and restore GPU inference pods in seconds.
R193 Hugging Face's own CDN: why model downloads break the web CDN model.