Skip to content

Conversation

svozza
Copy link
Contributor

@svozza svozza commented Sep 29, 2025

Summary

This PR adds the logic for returning streaming HTTP responses as currently supported by Lambda Function URLs. As event-handler does not currently support Function URLs, we are not exposing the final streamify function that users will use to enable streaming:

import {Router, streamify} from '@aws-lambda-powertools/event-handler/experimental-rest';

const app = new Router(); 

// ...

app.get('/test', ({event}) => {
  return {
    headers: {
      'content-type': 'application/json'
    },
    statusCode: 200,
    body: Readable.from(Buffer.from(JSON.stringify(event)))
  }
});

// ...

export handler = streamify(app);

This means that we will not have to have a long lived branch with the logic for this feature while we wait on Function URL support.

Changes

  • Add new resolveStream method that takes a Lambda ResponseStream as one of its arguments
  • Adds support for returning both Nodejs and web streams from middleware and route handlers but only when returned as a valid APIGatewayProxyResult type.
  • Unit tests for resolveStream method and assoicated helper functions.

Issue number: closes #4476


By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.

@svozza svozza self-assigned this Sep 29, 2025
@svozza svozza added the event-handler This item relates to the Event Handler Utility label Sep 29, 2025
@boring-cyborg boring-cyborg bot added dependencies Changes that touch dependencies, e.g. Dependabot, etc. tests PRs that add or change tests labels Sep 29, 2025
@pull-request-size pull-request-size bot added the size/XL PRs between 500-999 LOC, often PRs that grown with feedback label Sep 29, 2025
@svozza svozza requested review from dreamorosi and sdangol and removed request for dreamorosi September 29, 2025 15:53
@svozza svozza force-pushed the event-handler/streaming-response branch from 7a15cc4 to da7abb3 Compare September 29, 2025 16:07
Copy link
Contributor

@dreamorosi dreamorosi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the PR - I'll need a day or two to review and test it.

Looking forward to streaming!

@svozza svozza force-pushed the event-handler/streaming-response branch from da7abb3 to aee4058 Compare September 29, 2025 16:40
@pull-request-size pull-request-size bot added size/XXL PRs with 1K+ LOC, largely documentation related and removed size/XL PRs between 500-999 LOC, often PRs that grown with feedback labels Sep 29, 2025
Copy link
Contributor

@sdangol sdangol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added a few minor comments and questions

@svozza svozza force-pushed the event-handler/streaming-response branch 2 times, most recently from d44f4e4 to e9c29d3 Compare September 29, 2025 17:39
@svozza svozza force-pushed the event-handler/streaming-response branch from e9c29d3 to df92e5d Compare October 1, 2025 12:38
Copy link

sonarqubecloud bot commented Oct 1, 2025

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
3.9% Duplication on New Code

See analysis details on SonarQube Cloud

@svozza svozza requested review from dreamorosi and sdangol October 1, 2025 13:22
Copy link
Contributor

@dreamorosi dreamorosi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amazing work, this is really nice.

We should write a small short blog post on Builder Hub about this.

@svozza svozza merged commit e321526 into main Oct 1, 2025
38 checks passed
@svozza svozza deleted the event-handler/streaming-response branch October 1, 2025 14:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dependencies Changes that touch dependencies, e.g. Dependabot, etc. event-handler This item relates to the Event Handler Utility size/XXL PRs with 1K+ LOC, largely documentation related tests PRs that add or change tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature request: Handle Response Streaming in Event Handler

3 participants