Open jasonmccallister opened 2 years ago
Just to clarify, the Envoy proxy payload is not following the API Gateway v2 payload?
Something that will be on the new runtime i BREF-specific input that can be understood as an HTTP request, such as BREF_METHOD
and BREF_BODY
@mnapoli you can define payload_passthrough
as false and Envoy will transform the HTTP request into the following JSON payload:
{
"rawPath": "/path/to/resource",
"method": "GET|POST|HEAD|...",
"headers": {"header-key": "header-value", ... },
"queryStringParameters": {"key": "value", ...},
"body": "...",
"isBase64Encoded": true|false
}
@deleugpn would that mean we could set configure the handler to check for BREF_RESPONSE_V2
to force it to return API Gateway Version 2 responses?
@jasonmccallister ok so what is not working? Can you clarify what the problem is here?
and Envoy will transform the HTTP request into the following JSON payload:
Is that compatible with API Gateway payload v2?
@mnapoli there are two issues.
The Envoy request payload is not v2 compatible and is throwing an exception here.
The Envoy response is v2 compatible and only V2 compatible. However, Bref checks if the event is for format v2 and there is no way to override the response.
As far as #1, we could add another if statement that checks for $event['method']
that is sent by Envoy, but that won't resolve #2 where it has to return a v2 response.
We could resolve #2 by updating the code here to something like this:
public function isFormatV2(): bool
{
return $this->payloadVersion === 2.0 || array_key_exists('method', $this->event);
}
Diving through the existing code and talking it out here, it seems like it might not be a large lift to add support for this type of payload. Want me to make a PR with those proposed changes? I'm sure there are some other methods that will probably need updates.
Bref web functions expect to be invoked by either an API Gateway or ALB. It would be nice if Bref was able to handle HTTP events from different types of sources. However, there are many other invocation methods, including direct invocation using the AWS CLI, but invoking the lambda function without an API Gateway or ALB event type results in the following error (which is currently the expected behavior):
One tool that has Lambda integration is Envoy Proxy which requires the Lambda to return an API Gateway V2 type response but the incoming request/event looks like this:
I think there are some things to consider if this was to be implemented.
Accepting the event type We could update the HttpHandler to also accept the payload above, but then the response (as the code is right now) is looking for a version 2 in the payload to return the API Gateway V2 response.
Force returning V2 response That could be resolved by setting some kind of variable
BREF_RESPONSE_V2
(naming leaves a lot for desire) and when that is set the response will always be return as V2 compatible.Wanted to start the discussion before making a PR to add this feature.
Example with Envoy
If you wanted to try this with Envoy, you can use this Envoy configuration file (change
ACCOUNT
,FUNCTION
, andREGION
to the correct values) and runningenvoy -c envoy.yaml
.