Search code examples
amazon-web-servicesaws-api-gatewayopenapi

AWS API Gateway setting required headers - does not work


I create an api gateway and have included custom header fields like correlationId as required header inputs to its endpoint. When I deployed the APIGW, it does not work. I tried testing it, created a request with correlationId missing in the header, but no error was shown that the particular header field is missing. Same thing for format validation. Is there anything else I need to do to enable this validation?

I checked AWS APIGW docs and it said there should be validation once it has been set


Solution

  • Here is how you can do it:

    1. Make sure you have created REST API (Protocol: REST)
    2. In the API Gateway console, select your API.
    3. In the left-hand navigation pane, choose "Resources".
    4. Select the resource and the method for which you want to validate headers (something like GET - Method execution).
    5. Under the selected resource, choose "Method Request" and click "Edit".
    6. Under Method request settings select "Validate query string parameters and headers" from "Request validator" dropdown.
    7. Expand the "HTTP Request Headers" section and add header with flag "Required".

    Safe changes, redeploy API and after some small time you will see:

     {"message": "Missing required request parameters: [correlationId]"}
    

    for requests which doesn't have header correlationId