Motivation
AWS released preview response streaming support for .NET Lambda packages in release_2026-05-06:
Amazon.Lambda.Core 3.0.0: adds preview response streaming APIs.Amazon.Lambda.RuntimeSupport 2.0.0: adds runtime support for sending streaming responses.Amazon.Lambda.AspNetCoreServer(.Hosting): adds opt-in ASP.NET Core response streaming support.
MinimalLambda currently uses a buffered response model (Func<Stream, ILambdaContext, Task<Stream>>, InvocationDataFeature.ResponseStream = MemoryStream). That makes every response materialize before Lambda sends it. Response streaming would enable:
- lower time-to-first-byte for long-running handlers,
- LLM/token streaming and progressive output,
- large generated exports without buffering entire payloads in memory,
- responses above the classic 6 MB buffered payload limit where supported by Lambda invocation mode.
What AWS added
Public API surface in Amazon.Lambda.Core
New namespace: Amazon.Lambda.Core.ResponseStreaming
Important types:
LambdaResponseStreamFactoryCreateStream()CreateHttpStream(HttpResponseStreamPrelude prelude)
LambdaResponseStream : Stream- write-only
- non-seekable
BytesWritten
HttpResponseStreamPreludeStatusCodeHeadersMultiValueHeadersCookies
Key behavior from package source/docs:
- Once a Lambda function creates a response stream, all output must be written to that stream.
- Handler return value is ignored after stream creation.
CreateHttpStream writes an HTTP response prelude first; status/headers/cookies must be known before body bytes.- Feature is marked
[RequiresPreviewFeatures] and requires <EnablePreviewFeatures>true</EnablePreviewFeatures>.
Example shape:
#pragma warning disable CA2252varprelude=newHttpResponseStreamPrelude{StatusCode=HttpStatusCode.OK,Headers={["Content-Type"]="text/plain"}};awaitusingvarstream=LambdaResponseStreamFactory.CreateHttpStream(prelude);awaitstream.WriteAsync("hello\n"u8.ToArray());awaitstream.WriteAsync("world\n"u8.ToArray());
#pragma warning restore CA2252Runtime support in Amazon.Lambda.RuntimeSupport
The runtime support implementation:
- initializes a per-invocation stream context,
- starts a streaming HTTP POST to Lambda Runtime API,
- sends
Lambda-Runtime-Function-Response-Mode: streaming, - uses HTTP/1.1 chunked transfer encoding,
- writes errors via trailing headers (
Lambda-Runtime-Function-Error-Type, Lambda-Runtime-Function-Error-Body), - completes stream after handler returns or reports error.
Preview caveat from AWS package message: until managed .NET Lambda runtime client supports response streaming, use executable deployment with latest Amazon.Lambda.RuntimeSupport and enable preview features.
Proposed MinimalLambda support
Add response streaming as opt-in feature, not default behavior.
Possible API
Expose a MinimalLambda-owned abstraction so AWS preview types do not leak everywhere:
publicinterfaceILambdaResponseStreamingFeature{boolIsAvailable{get;}boolHasStarted{get;}StreamCreateStream();StreamCreateHttpStream(LambdaHttpResponsePreludeprelude);}publicsealedclassLambdaHttpResponsePrelude{publicint?StatusCode{get;set;}publicIDictionary<string,string>Headers{get;}=newDictionary<string,string>();publicIDictionary<string,IList<string>>MultiValueHeaders{get;}=newDictionary<string,IList<string>>();publicIList<string>Cookies{get;}=newList<string>();}Implementation can adapt to Amazon.Lambda.Core.ResponseStreaming.HttpResponseStreamPrelude internally behind #if NET8_0_OR_GREATER and preview warnings.
Pipeline behavior
- Register response streaming feature per invocation when available.
- If stream is created, skip normal buffered serializer/response stream path.
- If no stream is created, preserve existing behavior.
- Ensure only one stream can be created per invocation.
- Ensure status/headers are finalized before first body write for HTTP streaming.
- Decide error behavior:
- if error before stream creation: existing Lambda error path,
- if error after stream creation: let
Amazon.Lambda.RuntimeSupport report streaming trailers.
Host options
Possible opt-in:
builder.Services.Configure<LambdaHostOptions>(options =>{options.EnableResponseStreaming=true;});Need decide exact option location/name.
Targeting / dependencies
Likely requirements:
net8.0+ only for streaming implementation.Amazon.Lambda.Core >= 3.0.0.Amazon.Lambda.RuntimeSupport >= 2.0.0.<EnablePreviewFeatures>true</EnablePreviewFeatures> where streaming support is enabled/compiled.- AOT/trimming review: avoid reflection/dynamic paths.
Acceptance criteria
References
AWS release:
AWS Lambda response streaming docs:
AWS announcement/background:
aws-lambda-dotnet source areas to inspect:
Libraries/src/Amazon.Lambda.Core/ResponseStreaming/Libraries/src/Amazon.Lambda.RuntimeSupport/Bootstrap/ResponseStreaming/Libraries/src/Amazon.Lambda.AspNetCoreServer/ response streaming additions
Relevant upstream discussion/issues:
MinimalLambda current buffered areas to inspect:
src/MinimalLambda/Runtime/LambdaBootstrapAdapter.cssrc/MinimalLambda/Runtime/LambdaHandlerComposer.cssrc/MinimalLambda/Core/Features/InvocationDataFeature.cssrc/MinimalLambda/Core/Features/InvocationDataFeatureFactory.cs
Motivation
AWS released preview response streaming support for .NET Lambda packages in
release_2026-05-06:Amazon.Lambda.Core 3.0.0: adds preview response streaming APIs.Amazon.Lambda.RuntimeSupport 2.0.0: adds runtime support for sending streaming responses.Amazon.Lambda.AspNetCoreServer(.Hosting): adds opt-in ASP.NET Core response streaming support.MinimalLambda currently uses a buffered response model (
Func<Stream, ILambdaContext, Task<Stream>>,InvocationDataFeature.ResponseStream = MemoryStream). That makes every response materialize before Lambda sends it. Response streaming would enable:What AWS added
Public API surface in
Amazon.Lambda.CoreNew namespace:
Amazon.Lambda.Core.ResponseStreamingImportant types:
LambdaResponseStreamFactoryCreateStream()CreateHttpStream(HttpResponseStreamPrelude prelude)LambdaResponseStream : StreamBytesWrittenHttpResponseStreamPreludeStatusCodeHeadersMultiValueHeadersCookiesKey behavior from package source/docs:
CreateHttpStreamwrites an HTTP response prelude first; status/headers/cookies must be known before body bytes.[RequiresPreviewFeatures]and requires<EnablePreviewFeatures>true</EnablePreviewFeatures>.Example shape:
Runtime support in
Amazon.Lambda.RuntimeSupportThe runtime support implementation:
Lambda-Runtime-Function-Response-Mode: streaming,Lambda-Runtime-Function-Error-Type,Lambda-Runtime-Function-Error-Body),Preview caveat from AWS package message: until managed .NET Lambda runtime client supports response streaming, use executable deployment with latest
Amazon.Lambda.RuntimeSupportand enable preview features.Proposed MinimalLambda support
Add response streaming as opt-in feature, not default behavior.
Possible API
Expose a MinimalLambda-owned abstraction so AWS preview types do not leak everywhere:
Implementation can adapt to
Amazon.Lambda.Core.ResponseStreaming.HttpResponseStreamPreludeinternally behind#if NET8_0_OR_GREATERand preview warnings.Pipeline behavior
Amazon.Lambda.RuntimeSupportreport streaming trailers.Host options
Possible opt-in:
Need decide exact option location/name.
Targeting / dependencies
Likely requirements:
net8.0+only for streaming implementation.Amazon.Lambda.Core >= 3.0.0.Amazon.Lambda.RuntimeSupport >= 2.0.0.<EnablePreviewFeatures>true</EnablePreviewFeatures>where streaming support is enabled/compiled.Acceptance criteria
Streamwithout forcing bufferedMemoryStreamresponse.net8.0+).Amazon.Lambda.RuntimeSupport, function URL/API Gateway streaming invocation modes, and current preview caveats.References
AWS release:
AWS Lambda response streaming docs:
AWS announcement/background:
aws-lambda-dotnet source areas to inspect:
Libraries/src/Amazon.Lambda.Core/ResponseStreaming/Libraries/src/Amazon.Lambda.RuntimeSupport/Bootstrap/ResponseStreaming/Libraries/src/Amazon.Lambda.AspNetCoreServer/response streaming additionsRelevant upstream discussion/issues:
MinimalLambda current buffered areas to inspect:
src/MinimalLambda/Runtime/LambdaBootstrapAdapter.cssrc/MinimalLambda/Runtime/LambdaHandlerComposer.cssrc/MinimalLambda/Core/Features/InvocationDataFeature.cssrc/MinimalLambda/Core/Features/InvocationDataFeatureFactory.cs