serverless-http
serverless-http copied to clipboard
Streaming response
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?
I came here for the same question :)
Hey, Thanks for your lib :+1: I would also need this feature to increase payloads sizes for some routes of my API.
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
}
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!)
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?