API Gateway allows you to create, maintain and monitor your APIs on the AWS platform. When it comes to GET HTTP methods, there is a possibility to have query string parameters involved. API Gateway has a built-in method to validate query strings whenever a request is made to such a GET method and the request is allowed to proceed only if the API request contains the query string parameters mentioned in the API method. These validations involve making query string parameters required so the API request is going to fail if the required query string parameters are not provided.

Enabling query string parameter validation on AWS API Gateway

Enable Query String Validation

In order to enable this validation:

  • Open API Gateway console.
  • Click on your desired API.
  • Click ‘Resources’ on the left panel.
  • Click /methodName > GET (or ANY)
    • Click ‘Method Request’.
    • Under ‘Settings’:
      • Click ‘Request Validator’ pen button which will convert into a dropdown.
      • Choose ‘Validate query string parameters and headers’.
      • Save with the tick button.

Enter Query String parameters

Now to add a query string parameter:

  • Under ‘URL Query String Parameters’ on the same settings page:
    • Click ‘Add Query String’
    • Enter a name and save the value.
    • Mark the checkbox under the ‘Required’ column as per the requirements. Marking it will make this query string parameter required and the API request will fail if this parameter is not provided.
    • Click the tick button to save.