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

Streaming response #289

Open
hakog77 opened this issue Sep 11, 2023 · 5 comments
Open

Streaming response #289

hakog77 opened this issue Sep 11, 2023 · 5 comments

Comments

@hakog77
Copy link

hakog77 commented Sep 11, 2023

Hey, what is your opinion about streaming response? AWS announced support for streaming response for AWS Lambda with URL.

The idea is that the handler function is wrapped by streamifyResponse function (provided by AWS):

exports.handler = awslambda.streamifyResponse(
    async (event, responseStream, context) => {
        responseStream.setContentType(“text/plain”);
        responseStream.write(“Hello, world!”);
        responseStream.end();
    }
);

More documentation from AWS:
https://aws.amazon.com/blogs/compute/introducing-aws-lambda-response-streaming/

Is adding response streams something you would consider to support?

@johnimholawal
Copy link

I came here for the same question :)

@creativityjuice
Copy link

Hey,
Thanks for your lib 👍
I would also need this feature to increase payloads sizes for some routes of my API.

@jdrydn
Copy link

jdrydn commented Nov 10, 2023

After reviewing Introducing AWS Lambda response streaming, I've just read:

Writing the handler for response streaming functions differs from typical Node handler patterns. To indicate to the runtime that Lambda should stream your function’s responses, you must wrap your function handler with the streamifyResponse() decorator. This tells the runtime to use the correct stream logic path, allowing the function to stream responses.

... I think this means in order to support streaming, all responses would have to be "streamed" regardless if the response is a stream, something like:

import serverlessHttp from 'serverless-http';

 export const handler = awslambda.streamifyResponse(serverlessHttp(app, {
  streaming: true,
}));

And underneath, something like:

async (event, responseStream, context) => {
  responseStream.setContentType("application/json");
  responseStream.write(JSON.stringify(res.body));
  responseStream.end();
}

Even if the final response isn't a stream? I imagine that might be problematic?


Afterthought: It's a shame AWS didn't just iterate on their current APIGatewayProxyResult type, for example:

{
  statusCode: 200,
  headers: { ... },
  body: someReadStream,
  isReadableStream: true
}

@dougmoscrop
Copy link
Owner

dougmoscrop commented Nov 10, 2023

I think not only this, but the Function URL itself is configured for streaming or not. I don't remember if the payload indicates this, otherwise, it has to be a configuration option.

(but yes, supporting streaming here, is something I definitely want to support!)

@MNorgren
Copy link

I am also needing to support streaming in my AWS Lambda. Preferably only one a specific endpoint.

Has anyone already put together a workaround to get this to work until it is supported by this package?

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

6 participants