awslabs / aws-lambda-go-api-proxy

lambda-go-api-proxy makes it easy to port APIs written with Go frameworks such as Gin (https://gin-gonic.github.io/gin/ ) to AWS Lambda and Amazon API Gateway.
Apache License 2.0
1.03k stars 198 forks source link

How do I retrieve the ctx in http.Request after passing an APIGatewayProxyEvent through Gorillamux router #117

Closed estebane-frb closed 2 years ago

estebane-frb commented 2 years ago

I need AWS API gatewayProxyContext which is located within the http.Request passed by GorillaMux. However this context in within a nested context and I don't know how to retrieve it. Here is a screenshot of my debugger (ctx at the top is from http.Request obtained after passing ApiGatewayProxyEvent through gorillamux router)

image

Is there a recommended way to retrieve this? So far I've tried using github.com/apex/gateway's RequestContext but it can't find the gatewayProxyContext.

Appreciate any help!

coffeedome commented 2 years ago

Well looks like I just needed to use thee "GitHub.com/awslabs/aws-lambda-go-api-proxy/core" library. Like this:

apiGwCtx, ok := core.GetAPIGatewayContextFromContext(ctx)
if !ok{
  return errors.New("gatewayProxyContext not found")
}