-
Notifications
You must be signed in to change notification settings - Fork 11
Open
Description
As per the readme update, users can add headers and a status code to their streaming responses using a built-in helper method like so:
const { streamifyResponse } = require('lambda-stream')
const stream = require('stream')
module.exports.hello = streamifyResponse(
async (event, responseStream, context) => {
const metadata = {
statusCode: 200,
headers: {
"Content-Type": "application/json",
"CustomHeader": "outerspace"
}
};
// Use global helper to pass metadata and status code
responseStream = awslambda.HttpResponseStream.from(responseStream, metadata);
responseStream.write("Streaming with Helper \n");
await new Promise(r => setTimeout(r, 1000));
responseStream.write("Hello 0 \n");
await new Promise(r => setTimeout(r, 1000));
responseStream.write("Hello 1 \n");
await new Promise(r => setTimeout(r, 1000));
responseStream.write("Hello 3 \n");
responseStream.end();
// Suggested in Documentation: https://docs.aws.amazon.com/lambda/latest/dg/response-streaming-tutorial.html
// But NOT defined in node 16 or node 18
// Only defined in node 14
await responseStream.finished();
}
);
Would library users support shimming this method locally?
Should we consider wrapping this in Lambda as well? We could simply always return a ResponseStream with helper support. It seems to be a no-op if an empty object is passed as the metadata argument.
Thoughts?
mikeshot, orept, silvios, joehoyle, moltar and 5 more
Metadata
Metadata
Assignees
Labels
No labels