- Newest
- Most votes
- Most comments
AWS CloudFront, by default, does not forward the Host header to the origin because it uses this header to route requests to the correct location. This is why your API Gateway is failing when you try to forward this header -- it relies on the Host header to determine where to send the request. you cannot directly forward the Host header or X-Forwarded-Host header to the API Gateway using CloudFront without using Lambda@Edge or CloudFront Functions. These services allow you to modify the headers between the client and CloudFront or between CloudFront and the origin server. If your API needs the original Host header to function correctly, and you can't use Lambda@Edge or CloudFront Functions, you might need to consider a different design approach. Instead of relying on the Host header, you could use a custom header to pass the necessary information. You would set this header in your client application and configure CloudFront to forward it to your origin. Depending on the nature of your API and the information you're trying to pass, it might be possible to include it in the request body (for POST requests) or the URL (as a query string or part of the path).
Relevant content
- Accepted Answer
- AWS OFFICIALUpdated 8 months ago
- AWS OFFICIALUpdated 9 months ago
- AWS OFFICIALUpdated 2 years ago
- AWS OFFICIALUpdated 10 months ago
I'm confused because the document explains that you can forward the Host Header by creating a cache policy. From the documentation : "The values that you include in the cache key are automatically included in requests that CloudFront sends to the origin, known as origin requests." Below the link: https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/controlling-the-cache-key.html#:~:text=The%20values%20that%20you%20include%20in%20the%20cache%20key%20are%20automatically%20included%20in%20requests%20that%20CloudFront%20sends%20to%20the%20origin%2C%20known%20as%20origin%20requests.