Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS API Gateway: is it possible to include specific request body validation error in the response body?

I have an API Gateway POST endpoint that takes in a JSON request body. I have turned on the body request validator and added the request body model. However the error response I'm getting is only some generic message: "message": "Invalid request body" as defined in the Gateway responses. I'm wondering if it is possible to include the specific validation error in the response? In the logs it says specifically

Request body does not match model schema for content type application/json: 
[object has missing required properties (["property1","property2",...])] 

Is it possible to have something similar to this in the actual response? Thank you.

like image 813
tianz Avatar asked Nov 29 '17 23:11

tianz


People also ask

How do I pass AWS API gateway request body?

In the Mapping Templates area, choose an option for Request body passthrough to configure how the method request body of an unmapped content type will be passed through the integration request without transformation to the Lambda function, HTTP proxy, or AWS service proxy.

How do I add a request validator to AWS API gateway?

To enable a request validator on a methodCreate a new or choose an existing resource of the API. Create a new or choose an existing method the resource. Choose Method Request. Choose the pencil icon of Request Validator under Settings.

What are the three common ways you can interact with the API of AWS?

There are several ways to call this API. They include using the AWS Command Line Interface (AWS CLI), or by using an AWS SDK. In addition, you can enable API creation with AWS CloudFormation templates or (in the case of REST APIs and HTTP APIs) Working with API Gateway extensions to OpenAPI.

What is the role of the integration request in an API method in Amazon API gateway?

An integration request is an HTTP request that API Gateway submits to the backend, passing along the client-submitted request data, and transforming the data, if necessary. The HTTP method (or verb) and URI of the integration request are dictated by the backend (that is, the integration endpoint).


1 Answers

In Gateway response for error type BAD_REQUEST_BODY error status 400

set Application/json to {"message":$context.error.validationErrorString}

Ref https://stackoverflow.com/a/48014686

like image 122
Bhanwarlal Chaudhary Avatar answered Oct 15 '22 07:10

Bhanwarlal Chaudhary