I'm building an AWS API mail service that basically checks the body of the request before sending a mail with data from that body. It checks if every required parameter is there and does some basic checks if the data conforms to what we require.
The problem is, that even if the Lambda function throws an error (which I verified using the Lambda Test interface), the API Gateway returns a 200
response code with the error object as body
That means that I get a log like this:
Tue Apr 11 14:23:43 UTC 2017 : Method response body after transformations:
{"errorMessage":"\"[BadRequest] Missing email\""}
Tue Apr 11 14:23:43 UTC 2017 : Method response headers: {X-Amzn-Trace-Id=Root=************, Content-Type=application/json}
Tue Apr 11 14:23:43 UTC 2017 : Successfully completed execution
Tue Apr 11 14:23:43 UTC 2017 : Method completed with status: 200
Because of the last part, I believe API Gateway is returning 200
.
I did a couple of things to set up error handling:
- I added a second Method response for the error code:
- I added a second Integration response for the error code:
At this point I'm not sure why it still fails to return a correct response. I checked various posts about this (including: Is there a way to change the http status codes returned by Amazon API Gateway? and How to return error collection/object from AWS Lambda function and map to AWS API Gateway response code) and read the documentation.
I also tried the 'Lambda Proxy Way', but that didn't yield any results (the lambda didn't perform correctly at all that way'.
Does anyone see what I am missing here?