Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support lambda streaming responses #2

Open
GeoffreyBooth opened this issue May 16, 2023 · 5 comments
Open

Support lambda streaming responses #2

GeoffreyBooth opened this issue May 16, 2023 · 5 comments

Comments

@GeoffreyBooth
Copy link

Hi, thank you for creating this adapter! AWS lambda supports streamed responses now: https://docs.aws.amazon.com/lambda/latest/dg/configuration-response-streaming.html. This feature allows returning up to 20MB (up from the current limit of 6MB) and should provide a significant performance improvement for page load times as the page headers could be sent immediately while the body is rendered (possibly awaiting calls for data). Would you consider adding support for streaming to this adapter?

See also:

@tessellator
Copy link
Owner

Hey @GeoffreyBooth - thanks for reporting this! Yes, I will take a look at this when I get a chance (might be a couple of weeks).

@g-getsov
Copy link

g-getsov commented Oct 15, 2023

I've been looking into this a bit since I use this adapter and unfortunately Serverless Express doesn't currently support streaming (see CodeGenieApp/serverless-express#655). I also see that the response streaming logic present in the official adapter-node has been replaced with response buffering.
So it seems to me like the possible solutions to this are either to wait for Serverless Express to start supporting streaming or potentially move the adapter to use a middleware that supports streaming (I think at the moment the only one that does is Middy (see https://middy.js.org/docs/intro/streamify-response)).
Both of these solutions would also require the setResponse function to be updated to support streaming again (which should be just a copy and paste from the official adapter-node equivalent)

@tessellator
Copy link
Owner

Yeah, I am watching that serverless-express issue and hoping they can get someone to implement it soon, and I will update this adapter quickly afterward. I unfortunately do not have the time to do the work in serverless-express right now.

I haven't used Middy in production before, so I am hesitant to rewrite this adapter to use it.

@H4ad
Copy link

H4ad commented Jan 8, 2024

Sorry for marketing myself but I had a library serverless-adapter that already supports Streaming Responses.

But be aware the Streaming Responses has some quirks (aws/aws-lambda-nodejs-runtime-interface-client#94).

Currently, I don't support Polka but I can add support for that framework in a few hours (it's very simple).

@bytesnz
Copy link

bytesnz commented Sep 24, 2024

@H4ad, I'm having a crack at implementing this using your library at bytesnz#1 (will put a PR in @tessellator once I've got it working).

So far I've copied the updated handler from adapter-node and copied in the setup of serverless-adapter.
I've got it running, but it is currently just returning 0 byte responses. There's probably something simple I need to fix, so will have a look at it tomorrow. Feel free to point out the missing thing if you want to 😄

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

No branches or pull requests

5 participants