Open eschwartz opened 4 years ago
When you use the ProxyWithContext
method the Lambda and API Gateway context are added to the http.Request
context itself. See the addToContext
method.
The GetApiGatewayContext
method you are trying to use is there for when you use the Proxy
method. In that case the context object is serialized as a header in the request.
could you update the README this is a bit misleading, the method to extract RequestId listed in the readme does not work with the example provided in the README, it only works with Proxy
not ProxyWithContext
Does anybody know how to get APIGatewayContext when using ProxyWithContext?
Bumping this issue - the discrepancy in the docs is really frustrating on top of an already frustrating experience with AWS API Gateway (and that comes from a place of ❤️ ! I really want this to work).
@FirosStuart I think the intent is to use these core functions to get these values from the context in the ProxyWithContext
case https://github.com/awslabs/aws-lambda-go-api-proxy/blob/2a487f547914fe7cbf2d09f4a2834827c1080469/core/request.go#L234
That said, I'm still struggling to get it to work. Looks like that ☝️ gets the struct I'd expect, but it's not populated with any values. Still unclear if there's something wrong on my side. I stopped debugging it because I think I just want them in the HTTP request headers for portability (i.e. if I want to test things by sending http requests to a regular gin instance) and compatibility (if I want to back out of API Gateway + Lambda entirely).
FYI I was having similar issues - I could see the data coming in the initial RequestContext
on the event but not being able to access it via context.
Using GetAPIGatewayContextFromContext
instead of GetAPIGatewayV2ContextFromContext
worked for me.
I have code that looks something like:
The call to
muxLambda.GetAPIGatewayContext(r)
is returning an error:I'm not super familiar with the inner workings of this repo, but it looks like the
GetAPIGatewayContext
is expecting a custom"X-GoLambdaProxy-ApiGw-Context"
header to be set elsewhere in the code, before my route handler is called. It looks like theProxy()
method results in the header getting set (by callingProxyEventToHTTPRequest
, which callsaddToHeader
), but theProxyWithContext
method doesn't follow this same code path.Is this a bug in the
ProxyWithContext
method, or maybe I'm misunderstanding how this is supposed be used?