sst
sst copied to clipboard
Feature Request: awslambda.streamifyResponse
https://aws.amazon.com/cn/blogs/compute/introducing-aws-lambda-response-streaming/
+1
Any idea on how this can be solved? It seems perfect for prototyping the openAI streaming option. Is there an option to upload a custom lambda function to use the new streamifyResponse decorator?. Could not figure out a way from the samples. thanks
We'll need to take a look into this. We haven't gotten to it yet.
https://github.com/astuyve/lambda-stream
I can use streamifyResponse feature with this package, but currently only using for Lambda Function. And you have to configure Invoke mode to RESPONSE_STREAM
as a heads up, i'm about to submit a PR for adding streaming to AstroSite
; hadn't thought about how that might be generalized to Function
much, but i know there are challenges there.
edit: PR submitted, happy to assist with applying this elsewhere if anyone is looking for it.
@adamelmore I'm looking to apply this to SveltekitSite. Seems like SvelteKit handles SST out of the box, so I'm hoping this should be a similar process to your Astro PRs. Let me know if I'm missing something.
I need similar support for React apps too. Anyone with any ideas ?
@DanaBrev what kind of React apps?
bum @jayair I'm looking for something similar, for a NextJS app, I'm already using NextjsSite constructor and I'm creating an Api construct that should stream down to the nextjs website the response. Is there workaround for this at the moment? Thanks
Nextjssite should support streaming. But the API won't because AWS' API Gateway doesn't support streaming.
Yea I figured, I made it work by calling the lambda endopint directly and with the lambda-stream package for local dev
edit: PR submitted, happy to assist with applying this elsewhere if anyone is looking for it.
any plans on making SvelteKit support streaming? i found this repo but it seems like it remove a bunch of functionality (a lot of commented code): https://github.com/sdocquir/svelte-kit-sst-streaming
Still waiting on AWS to fix streaming on Lambda. Apparently they are working on a fix.
Still waiting on AWS to fix streaming on Lambda. Apparently they are working on a fix.
So currently it's not working for any service, not just SST?
Yeah, got an update that they are rolling it out to all regions this week.
Streaming works for me using this code, but it seems that is has some fixed amount of either bytes or seconds that it still does a buffer and afterwards start to actually stream.
export const handler = awslambda.streamifyResponse(
async (event, responseStream, context) => {
const httpResponseMetadata = {
statusCode: 200,
headers: {
//use what makes more sense to your useCase
//"Content-Type": "text/event-stream"
//"Content-Type": "text/plain"
"Content-Type": "text/html"
}
};
responseStream = awslambda.HttpResponseStream.from(responseStream, httpResponseMetadata);
const text = `<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas blandit mollis risus vel ornare. Maecenas suscipit mauris eget lacus efficitur, id tristique lorem sodales. Aliquam commodo purus lacus, et pulvinar diam mattis at. Etiam scelerisque non enim sed lobortis. Interdum et malesuada fames ac ante ipsum primis in faucibus. Sed ipsum lacus, porttitor a tincidunt quis, mattis vel urna. Praesent facilisis risus augue, nec tristique tellus sodales in. Donec mattis massa nec enim laoreet, a porttitor tellus molestie. Phasellus justo libero, faucibus sit amet leo sit amet, cursus consectetur ligula. In dui diam, malesuada posuere justo eu, malesuada condimentum sem. Nullam nec ornare magna. Maecenas quis eros ut metus elementum vehicula a at erat.
Etiam molestie mollis ante. Aliquam mollis imperdiet diam at luctus. Integer leo dui, sagittis nec nibh luctus, porta cursus velit. Nullam nec posuere sem. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec congue cursus erat ut fermentum. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Morbi viverra, nisi eget finibus rhoncus, mauris nunc tincidunt neque, a vestibulum elit magna id arcu.
Curabitur pellentesque mauris quis purus volutpat imperdiet. Ut nec risus felis. Ut in diam lorem. Cras ut risus quis odio aliquet vehicula. Phasellus porta eu magna eget pulvinar. Quisque laoreet nisl varius ultrices tincidunt. Nam scelerisque metus at metus aliquam bibendum. Pellentesque lorem mi, scelerisque sit amet sem ut, aliquam sollicitudin libero. Suspendisse a massa quis nibh viverra consectetur consequat a elit. Mauris at hendrerit augue, ut laoreet lacus. Phasellus dignissim erat vitae sollicitudin aliquam. Nunc et efficitur mi. Nunc sit amet semper est, a fringilla nisl.
Sed varius leo mauris, id dignissim magna scelerisque id. Maecenas bibendum neque at risus feugiat, sed consequat augue cursus. Vivamus lacinia augue risus, eu dapibus leo fringilla eget. Curabitur pharetra in arcu quis fermentum. Vivamus felis ipsum, maximus sed vestibulum vitae, sodales sed lorem. Maecenas a tellus nec dui scelerisque aliquam. Praesent pretium consequat leo, a tincidunt turpis feugiat et. In euismod ex nec elementum interdum.
Ut ac nunc non mauris mollis euismod vitae dignissim sem. Sed ut molestie dolor, id scelerisque odio. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Phasellus iaculis justo lacus. Duis congue ac magna vitae laoreet. Suspendisse lobortis facilisis tellus laoreet consectetur. Fusce rhoncus fermentum odio. In venenatis, sapien ac pharetra ullamcorper, est ipsum vestibulum turpis, ac tincidunt ante magna in nisl. Nam ultrices feugiat eros. Proin fermentum massa ut mauris fermentum, at rutrum elit maximus. Nullam dignissim nibh eget augue venenatis, id tincidunt elit efficitur. Nullam nec diam vitae mauris mattis venenatis. Morbi molestie nec sem eget dignissim. Praesent imperdiet magna purus, sit amet commodo mi cursus sit amet. Nam eget velit ac nulla bibendum varius ac lacinia neque.
<p>`;
for (let i = 0; i < 100; i++) {
responseStream.write(text);
await new Promise(r => setTimeout(r, 1000));
}
responseStream.end();
}
);
Yeah that's the bug. We checked today, it hasn't been fixed yet.
Is there any place that the "bug" is tracked, like a Github issue on some repo?
I'm not sure if there's one on the AWS side because it's an internal issue. But we personally check it every few days.
Hoping that this will also become available for RemixSite 🤞🏻 I'd like to use Remix Streaming but it's unclear how to do so when deploying with SST/ if it is currently supported (works locally of course, but not with site server lambdas)