Skip to content

Comments

Add support for Lambda Response Streaming#2288

Draft
normj wants to merge 13 commits intodevfrom
normj/response-streaming
Draft

Add support for Lambda Response Streaming#2288
normj wants to merge 13 commits intodevfrom
normj/response-streaming

Conversation

@normj
Copy link
Member

@normj normj commented Feb 19, 2026

In draft mode while still cleaning up the experience

Issue #, if available:
#1635

Description of changes:
Integrate Lambda response streaming support into the Amazon.Lambda.RuntimeSupport.

A hello world example of using response streaming. In this case sense I wrapped the Stream returned from CreateStream in a StreamWriter the writes will be buffered in StreamWriter till the buffer is full. I call the flush method every 10 iterations to force sending data back to the client.

using Amazon.Lambda.Core;
using Amazon.Lambda.RuntimeSupport;
using Amazon.Lambda.Serialization.SystemTextJson;

// The function handler that will be called for each Lambda event
var handler = async (string input, ILambdaContext context) =>
{
    using var responseStream = LambdaResponseStreamFactory.CreateStream();
    using var writer = new StreamWriter(responseStream);
    for (var i = 0; i < 100; i++)
    {
        var message = $"Hello {input} - {i}";
        await writer.WriteLineAsync(message);

        if (i % 10 == 0)
        {
            await writer.FlushAsync();
            await Task.Delay(1000);
        }
    }
};

// Build the Lambda runtime client passing in the handler to call for each
// event and the JSON serializer to use for translating Lambda JSON documents
// to .NET types.
await LambdaBootstrapBuilder.Create(handler, new DefaultLambdaJsonSerializer())
        .Build()
        .RunAsync();

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@normj normj marked this pull request as draft February 19, 2026 01:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant