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

NewV2 method cause 404 error,but the New method is ok #130

Open wangliguokaka opened 2 years ago

wangliguokaka commented 2 years ago

code: func main() {

http.HandleFunc("/ok", func(w http.ResponseWriter, r *http.Request) {
    w.Header().Add("Content-Type", "application/json")

    w.WriteHeader(200)
    io.WriteString(w, "ok")

})

http.HandleFunc("/test", func(w http.ResponseWriter, r *http.Request) {
    w.Header().Add("Content-Type", "application/json")

    w.WriteHeader(200)
    io.WriteString(w, "test")
})

lambda.Start(httpadapter.NewV2(http.DefaultServeMux).ProxyWithContext)

}

error : image

image

rajrohanyadav commented 2 years ago

Hi, I'm also facing exactly the same issue with my API. I debugged and found, that when using NewV2, it puts a test/ before the actual requested path, which causes the 404. e.g. Expected req path: req.RequestContext.HTTP.Path = /api/v1/cats Actual req path: req.RequestContext.HTTP.Path = /test/api/v1/cats

EDIT: With SAM local, the req path is formed correctly and all the API endpoints are reached fine. But after deployment to AWS API Gateway it doesn't seem to work. (I'm using AWS::Serverless::HttpApi)

esoteloferry commented 12 months ago

I have same issue with HTTP (v2) gateway but adding test did not work @rajrohanyadav

@wangliguokaka did you find a solution you can share?