I've an AWS API gateway in front of a REST API service. I would like to remove one/some HTTP headers when I forward the request to the origin.
I know how to do this using a lambda but I'm just wondering is there is something built in.
I've an AWS API gateway in front of a REST API service. I would like to remove one/some HTTP headers when I forward the request to the origin.
I know how to do this using a lambda but I'm just wondering is there is something built in.
The easiest thing to do something similar is to force a given header to be an empty string.
To do this you can go in "Integration Request" panel (the second block of an API Gateway request/response flow):
In Headers block you should find all the headers defined (if you've defined it when creating the API resource) with the related mapping. If you wish you can edit the mapping replacing the method.request.header.headerThatYouWantToRemove
string with just ''
(note the two single quotes) for the header that you want to unset.
If the header that you wish to unset is not present, you can be add it using "Add header" link.
At this point the backend endpoint should ignore empty headers and you are done.
Instead, if you wish to completely delete the header you have to play with mapping template and Velocity mapping template, but this can be risky and error-prone.
Using VTL you can do this.
#if($paramName == "Authorization")
"$paramName" : ""
#else
"$paramName" : "$util.escapeJavaScript($params.get($paramName))"
#end