I'm using AWS API Gateway and its HTTP Proxy.
I need to pass the CloudFront-Viewer-Country
header to my endpoint. I tried following the same setup outlined in the following question
Access headers in AWS API Gateway using HTTP Proxy?
and I'm getting the following headers on my endpoint server.
Array
(
[host] => example.com
[Accept] => application/json
[User-Agent] => AmazonAPIGateway_c8752844lh
[x-amzn-apigateway-api-id] => c8752844lh
[X-Amzn-Trace-Id] => Root=1-59bd7a5e-003ef07b3c4c3680299801f1
[X-Forwarded-For] => xx.xxx.xx.xxx
[X-Forwarded-Port] => 443
[X-Forwarded-Proto] => https
[Connection] => keep-alive
)
However, the CloudFront-Viewer-Country
is not among them. If I used a lambda function instead of HTTP Proxy, I can see a lot more headers (including the CloudFront-Viewer-Country
).
Could anyone please tell me how to access the required header on my endpoint using HTTP Proxy ?
For the resource and method where you want the header, go to Method Request → HTTP Request Headers → Add Header and set the Name as CloudFront-Viewer-Country
. Click the circled checkmark to add. This exposed the header to the remainder of the execution flow.
Then, in Integration Request → HTTP Headers → Add Header.
Set the Name to CloudFront-Viewer-Country
and set Mapped from method.request.header.CloudFront-Viewer-Country
and click the circled checkmark to add. This picks up the exposed header and adds it to the request that is forwarded to your back-end.
Deploy the API.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With