Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does API Gateway automatically validate input model?

I've created simple API in AWS API gateway with following endpoint:

POST /v1/users

In method execution / method request I've added request model:

enter image description here

This model schema looks like this:

enter image description here

However when I make a request to that endpoint with json body { "foo": "bar" } it does not reject it and my lambda function is executed...

So why there is option to define JSON schema if it is not used to validate requests?

like image 451
user606521 Avatar asked Aug 28 '15 11:08

user606521


People also ask

Does API gateway automatically scale?

Amazon API Gateway acts as a proxy to the backend operations that you have configured. Amazon API Gateway will automatically scale to handle the amount of traffic your API receives.

What can be used to validate API input?

Using JavaScript to Validate API Response Bodies In your API Science monitor, you can use JavaScript to validate any of these fields.

How do I validate request body Amazon API gateway?

To enable basic validation, you specify validation rules in a request validator, add the validator to the API's map of request validators, and assign the validator to individual API methods. Request body validation and request body passthrough are two separate issues.

How do I validate headers in API gateway?

Go to the Integration Request tab of your endpoint, click Mapping Templates , set Request body passthrough to never , add a mapping template for application/javascript , and click Method Request Passthrough from the dropdown next to Generate template .


3 Answers

Just trying to figure this out myself, and I see you also only just asked this a few hours ago!

So far the only reference I've found is here:

http://docs.aws.amazon.com/apigateway/latest/developerguide/how-to-method-settings.html

For non-GET method types, expand Request Models, and for Content Type and Model name, type the content type and choose the name of a model that will transform caller-supplied data into the expected format.

So seems it's more for transformation than validation - but it's not particularly clear how this actually works.

UPDATE

I just noticed this HackerNews thread:

https://news.ycombinator.com/item?id=9880683

One of the AWS engineers responded on there, and said:

Models are not required for validation. They are simply used to generate the objects in the client SDKs.

like image 63
RemoteCTO Avatar answered Sep 29 '22 01:09

RemoteCTO


This feature has been released as of 04/11/2017. See https://aws.amazon.com/blogs/compute/how-to-remove-boilerplate-validation-logic-in-your-rest-apis-with-amazon-api-gateway-request-validation/

like image 32
RyanG Avatar answered Sep 30 '22 01:09

RyanG


Anyway input/model validation at the API Gateway should only be considered as an additional layer of defence from a security point of view.

Your service MUST always validate the inputs/models it's not something you can delegate!

like image 38
Daniel Gartmann Avatar answered Oct 01 '22 01:10

Daniel Gartmann