2

So, I've heard about request validator in API gateway.

Is it possible to validate request if it has atleast 1 parameter/querystring?

Example: Either name or id should be in the query string

https://something.domain.com/dev/employee?name=myname https://something.domain.com/dev/employee?id=myid

Basically, what I want is that before a Lambda function is executed, this should consider these conditions first

  • SHOULD have a parameter

  • Either a name or an id should be in that parameter

Steven
  • 821
  • 1
  • 10
  • 24
  • Possible duplicate of [How to pass a querystring or route parameter to AWS Lambda from Amazon API Gateway](https://stackoverflow.com/questions/31329958/how-to-pass-a-querystring-or-route-parameter-to-aws-lambda-from-amazon-api-gatew) – Dmitry Grinko Nov 24 '17 at 11:48
  • That one is more of "how to pass a parameter". My question is on "how to validate the request parameters" – Steven Nov 24 '17 at 12:01
  • Basically, what I want is that before a Lambda function is executed, this should consider these conditions first - Should have a parameter - Either a name or an ID should be in that parameter – Steven Nov 24 '17 at 12:02
  • I updated my answer – Dmitry Grinko Nov 24 '17 at 12:15
  • I suggest looking at the answer by Vijayanath. API Gateway supports request validation prior to calling the Lambda function, however it only supports 'required' parameters. Hopefully you can re-design your API structure slightly to take advantage of the functionality that API Gateway supports. – jackko Nov 28 '17 at 17:15

1 Answers1

1

API Gateway can perform the basic validation. For the basic validation, API Gateway verifies either or both of the following conditions:

  • The required request parameters in the URI, query string, and headers of an incoming request are included and non-blank.

  • The applicable request payload adheres to the configured JSON-Schema request model of the method.

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.

Please read documentation here

Vijayanath Viswanathan
  • 8,027
  • 3
  • 25
  • 43