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.05k stars 197 forks source link

How to return error so it's recorded in lambda error count #48

Open terrywarwar opened 4 years ago

terrywarwar commented 4 years ago
func handler(w http.ResponseWriter, r *http.Request) {
      if err != nil {
        http.Error(w, err.Error(), http.StatusBadRequest)
        return
    }
}
sapessi commented 4 years ago

Good question. The only easy way to do it right now is to have the entire function fail (panic()). However, in this case API Gateway will return 504 or 502. Unfortunately because of the way API Gateway and Lambda work together it is very hard to throw an error in the Lambda function to have it recorded as a Lambda execution error and also have API Gateway return a human-readable response.