I would like to proxy the incoming requests to different endpoints based on a request header received in the request.
In AWS API gateway, I can set up different endpoints as separate stage variables but at integration >> Endpoint URL setting, I would like to pick the stage variable based on the value of request header value.
For example:
if header value is brand-id: abc then request should be proxied to abc.test.com
if header value is brand-id: pqr then request should be proxied to pqr.test.com
I'm expecting something like this in "Endpoint URL" value: http://${stageVariables.${method.request.header.brand-id}}/
Any help to achieve this would be appreciated.
You can use Lambda Proxy Integration to achieve the similar behavior:
You can use python's adapter pattern, or string parameter formatting to save yourself from the clutter of if and else conditions. You can also consider calling Lambdas directly from your proxy Lambda with
RequestResponse
invoke, that may save yourself some time caused by the extra layer of API Gateway.