I have an API Gateway that is one of many origins behind a CloudFront distribution that I created. I am trying to forward certain headers to origins (Host, Origin, among others). When I do not forward any headers, the requests reach the API Gateway just fine. However, as soon as I enable header forwarding in the CloudFront distribution (either All or Whitelist) the API Gateway is no longer able to handle the requests. I get the following error:
ERROR
The request could not be satisfied.
CloudFront wasn't able to connect to the origin.
Any advice on fixing this problem?
CloudFront also forwards the headers that it forwards by default, but it caches your objects based only on the headers that you specify. Forward only the default headers. In this configuration, CloudFront doesn't cache your objects based on the values in the request headers.
If your API clients are geographically dispersed, consider using an edge-optimized API endpoint in API Gateway. This type of endpoint acts as a Regional endpoint with an AWS managed CloudFront web distribution to improve client connection time.
To pass custom headers from an API Gateway API to a Lambda function, use a body mapping template. The API sends the updated API request to a Lambda function to process the headers. Then, the Lambda function returns one or more header values from the original API request.
As commented above, you can't forward the Host header to the API Gateway origin. Without the Host header, API Gateway doesn't know what API is being invoked.
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