Closed thekid closed 11 months ago
the requirement to either extend HttpIntegration or ApiGateway to distinguish between the usecases. Extending from HttpApi will raise an error
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!
This PR implements HTTP response streaming on top of https://github.com/xp-forge/lambda/issues/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.⚠️ This PR will therefore be released in the next major version,
2.0.0
at the time of writing.See also