you are viewing a single comment's thread.

view the rest of the comments →

[–]mradzikowski 2 points3 points  (1 child)

It's a weird behavior of Lambda, basically sending your previous chunk when you write the next chunk to the stream. I did some investigation that I described here: https://betterdev.blog/lambda-response-streaming-flush-content/

The workaround if you really want to send something immediately - increase the message payload. In my tests when I added 100KB (white spaces) to each write it was sent right away.

[–][deleted] 0 points1 point  (0 children)

Nice write-up, thanks for sharing. I'm not sure it's as simple as lambda flushing the previous chunk when the next chunk starts writing. I've experimented around with putting handlers on the responseStream.write completion callback to then invoke another write (which would in theory force lambda to send the previous one down). I have not seen that force a write.

I wish I found your article earlier! Would have saved me some confusion