Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS API Gateway behind CloudFront, forwarding headers?

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?

like image 393
Marty Avatar asked Feb 15 '17 16:02

Marty


People also ask

Does CloudFront forward headers?

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.

Can I use CloudFront with API gateway?

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.

How do I pass headers in API gateway?

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.


1 Answers

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.

like image 191
jackko Avatar answered Oct 17 '22 08:10

jackko