tessellator / sveltekit-adapter-lambda

Adapter for SvelteKit applications that generates a handler for use on AWS Lambda
MIT License
13 stars 0 forks source link

Support lambda streaming responses #2

Open GeoffreyBooth opened 1 year ago

GeoffreyBooth commented 1 year ago

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 commented 1 year ago

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 commented 8 months ago

I've been looking into this a bit since I use this adapter and unfortunately Serverless Express doesn't currently support streaming (see https://github.com/vendia/serverless-express/issues/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 commented 8 months ago

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 commented 6 months ago

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 (https://github.com/aws/aws-lambda-nodejs-runtime-interface-client/issues/94).

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