-
Notifications
You must be signed in to change notification settings - Fork 556
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
Handler design for streaming responses #500
Comments
To add to this, using Note that the streams implementation should respect the |
It's not :) The plumbing in #494 is the bare-minimum addition so that current users of
This is where I've had trouble in designing an singular There can of course be an additional Function URL specific interface that stacks ontop of a lower level
Do you have an opinion on mimicking |
I'd be OK with a pairing like
My lingering doubt is, if we do something that ties into the http stdlib, should we just go all way way to doing something like the following:
|
Ah, that makes perfect sense now. I couldn't understand the purpose of #494 in isolation, but allowing larger payloads explains it. HTTP responses
I still err on the side of selfishly answering "yes, it would be great to have that functionality in aws-lambda-go", but I'm not responsible for maintaining it 😅
I feel it would make sense to go all the way. I would probably also expect the underlying
If it didn't work in all those scenarios, it could potentially be a liability: I could imagine people trying to use it with APIGW, it failing, and issues being opened on GitHub. Non-HTTP responses |
Yeah there's a lot to get wrong in trying to support all the existing http proxy integrations. I think I wanna namespace any new |
Closing this. https://github.com/aws/aws-lambda-go/releases/tag/v1.41.0 added the If Lambda ever opens up the ability to do something clever with the Runtime API Response Content-Type, then I belive something like a handler entry with a |
AWS recently released support for streaming responses from Lambda functions. I can see that work is currently underway to add this to the Go SDK in #494, #495. It might be too late, but I'd like to raise an alternative API design for your consideration.
Is your feature request related to a problem? Please describe.
Right now it looks like streaming responses will be supported by having a handler function return an
io.Reader
. I think that this could potentially make the implementation of streaming-response Lambda functions more error-prone and provide less control over the streamed output than using anio.Writer
.My understanding is that a streaming response handler ~today should be implemented like this:
Describe the solution you'd like
Consider a handler signature like this:
This handler signature avoids the necessity of spawning a goroutine and recovering from panics in it. It allows for standard error handling conventions. It also allows the user to have control over the size of the response chunks.
This potential design doesn't address how Lambda function URL response streaming would work. The
application/vnd.awslambda.http-integration-response
content-type doesn't appear to documented yet, but I've figured out how it works from #494. I can think of two options.The first option is that there can be a
lambda.WriteResponseHeaders(writer io.Writer, statusCode int, headers map[string]string, cookies []string)
helper function that the user calls to write the prelude before streaming their response body. This would suffer from the issue of being non-obvious and users would have to read the docs to know that they need to use it.The second option is that we can copy the design of stdlib
http.Handler
and instead of a plainio.Writer
, we pass in alambda.StreamingResponseWriter
, e.g. like so:I haven't fully thought through this second option yet. I think there's definitely value in the familiarity aspect - most Go developers will recognise the
http.Handler
-like signature and know how to use it. An outstanding question on my mind is "do we need to support non-function URL streaming responses?" i.e. does there need to be a way to set the "top-level" content-type and not just a content-type within the function URL response "prelude". But it seems like the ability to set that content-type doesn't yet exist today anyway so maybe it's not necessary 🤔Additional context
I noticed that the
Lambda-Runtime-Function-Response-Mode: streaming
request header isn't set anywhere yet. Is it not needed?I'm also aware that supporting a second handler type might be a bigger undertaking than squeezing support in via an
io.Reader
return type. I just wanted to mention the alternatives to see if they had been considered yet.Supporting two different handler signatures might seem to over-complicate the package, but I also suppose it would match the Node.js library introducing the
awslambda.streamifyResponse
decorator and inner function with three parameters.The text was updated successfully, but these errors were encountered: