-
Notifications
You must be signed in to change notification settings - Fork 0
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
Implement HTTP response streaming #10
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Uses buffering as streamed responses are not supported by API Gateway
thekid
commented
Jun 18, 2023
This incorporates the following class hierarchy: package com.amazon.aws.lambda:
+ HttpApi
|- HttpIntegration
`- ApiGateway Maybe, we can work around this as follows: package com.amazon.aws.lambda:
+ HttpIntegration // New base class
|- HttpApi // Uses buffered response mode, as before
`- HttpStreaming // Name it as it is 🙂 This way, we can avoid the BC break! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR implements HTTP response streaming on top of xp-forge/lambda#23 (Implement streaming lambda responses), improving TTFB and memory consumption of web applications. Response streaming is available for lambda function URLs which have their invoke mode set to RESPONSE_STREAM.
Setup
To integrate with lambda function URLs, extend from the new HttpStreaming base class.
👉 Verify RESPONSE_STREAM is set:
The AWS CLI provides an option to change the invoke mode:
If not set, the following will be displayed:
💡This is implemented by setting
body
to this error message in the meta information. The BUFFERED response handler will use this for the body, while RESPONSE_STREAM will recognize the specialapplication/vnd.awslambda.http-integration-response
mime type and will stream everything after the delimiter. This adds an overhead of 34 bytes to each payload, which seems acceptable for the sake of mitigating a big WTF factor.API Gateway
Streamed responses are not supported by API Gateway’s LAMBDA_PROXY integration. To integrate with it, extend the HttpApi base class instead, as before.
💡Also use this for integrating with function URLs when their invoke method needs to be set to BUFFERED.
BC Break
This PR breaks BC due to the dropped compatibility with older
xp-forge/lambda
versions. Older versions will not have the streaming functionality backported. Composer will show an error for mismatches.2.0.0
at the time of writing.See also