Api Gateway with Cloudflare Loadbalancer

We have two cloudfront distributions hosted on AWS, they each points to a specific CNAME

api-beta → randomstrbeta . cloudfront . net
api-prod → randomstrprod . cloudfront . net

I created a pool on cloudflare pointing to these hosts
api-beta . domain . com
api-prod . domain . com

The records of each one of those points correctly to the respective cloudfront.net hostname

Finally, the load balancer name on cloudflare side is api-test.domain.com (yes for testing purposes before the final changes)

The problem is, the cloudfront distributions need to be reached by their respective name, this means, I need to set their aliases to api-test . domain . com on both of them, but AWS does not allow for two cloudfront distributions to answer on the same CNAME, which makes it impossible to set up the load balancer on cloudflare side.

So, I 'm looking into probable solutions to this scenario.

The desired behavior is to have both cloudfront distributions (both apigateways) replying under the same CNAME via the Cloudflare’s load balancer service.

I tried the “custom domain” feature with the API Gateway configuration but the problem is the same, because the API Gateway will reply in accordance to the hostname requested, so if I request api-test.domain.com, i get an 403 Forbidden but when I point it directly to the CNAME specified as custom domain, I get the expected answer from the server.

I would like to know if there is some feature under Cloudflare that will help me in achieving this.

Any help in this matter will be appreciated, regards.

What if you try to override the Host header?

2 Likes

Thanks a lot, it worked in pair with API Gateway custom domains.

2 Likes

My pleasure.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.