Get detailed error messages from AWS API Gateway Request Validator

旧时模样 提交于 2019-11-28 21:19:02

(Developer on API Gateway)

Unfortunately, this is not supported right now. We are actively working on fixing this issue, but I can't give you any specific timelines by when this could be supported.

Since a API Gateway developer had answered the question, I still want to add some tips for you, maybe it is helpful and that can be an accepted answer!

For your question, in fact you need to active the cloudwatch logs for api gateway, with that, you can get more logs than you have before.

Let me know if it included the details for Request Validator

This aws document - How do I enable Amazon CloudWatch Logs for APIs I created in the Amazon API Gateway? gives the steps on how to enable it.

But I prefer to go with this document API Gateway and Lambda Logs, which give the screenshots to follow up easily.

In your api gateway, you should see this is enabled.

Access the API gateway several times, go through the log group which is named as:

API-Gateway-Execution-Logs_{rest-api-id}/{stage_name}

Which has more details than the information you have as Invalid request body and others, such as {"message": "Internal server error"}. It is very useful feature, that save me a lot time troubleshooting serverless and api gateway issues.

This is not an answer to your question but rather an alternative workaround that we've used in our apps that serves the same purpose (request validation).

Our serverless API started by defining all our endpoints in API Gateway (complete with Swagger documentation). Over time, we've added a lot more endpoints (around 60+ endpoints consisting of legacy REST endpoints, public REST endpoints, and private graphQL endpoints).

Managing this number of endpoints through API Gateway proved to be very tedious, and deploy time took very long (we we're using serverless).

Eventually, we decided to reduce it into three "monolith" serverless applications. Two REST endpoints and one GraphQL endpoint.

So basically, we handled the routing inside our Lambda handlers (and routing is not necessary for GraphQL).

For request validation, it comes for free with GraphQL (another reason to love GraphQL). As for our REST handler, we use JSON schemas and any validation error, we can easily return back to the client together with an HTTP 400 error message.

sandesh

In this case, within the Gateway Responses section, go to:

Bad Request Body [400]

Change the value of the body mapping template to: 

{"message":$context.error.validationErrorString}

Ex Output:

{
"message": "[instance value (\"us\") not found in enum (possible values: [\"usd\",\"eur\",\"gbp\",\"jpy\",\"aud\",\"chf\",\"cad\",\"nzd\"])]"
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!