Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DNS setup from Cloudflare to Amazon API Gateway

I have a website mydomain.com with the DNS configured through Cloudflare. I am in the process of setting up an API accessible through api.mydomain.com

The servers I use are hosted on Digital Ocean, but I would like to use some of the features of the Amazon API Gateway Interface (I will later be migrating all servers over to Amazon). The API server is the same as the website (again this will later be separated, but for now the effective A record is the same Digital Ocean node). The API Gateway Interface is configured and I can access it just fine through the provided endpoint someamazonendpointurl.com/stage

On Amazon I have created a Cloudflare distribution with origin api.mydomain.com. It has some basic HTTP to HTTPS behaviours along with query string parameters. I then set a CNAME record on Cloudflare to point to the endpoint URL. When I try and access api.mydomain.com though I get the Chrome error:

ERR_TOO_MANY_REDIRECTS

Does anyone have any idea what I might have misconfigured. I realise this is a bit of an odd setup, but it is a stop-gap while we migrate our servers over to amazon.

UPDATE

I noticed I had a CNAME record in cloudfront to api.mydomain.com. I've now removed this but get:

ERROR

The request could not be satisfied.

Bad request. 
Generated by cloudfront (CloudFront)
Request ID: <id>
like image 590
Silian Rails Avatar asked Apr 19 '16 08:04

Silian Rails


People also ask

Can I use Cloudflare with AWS?

Cloudflare integrates quickly and easily with AWS. Host your websites and run applications on AWS while keeping them secure, fast, and reliable. Use Cloudflare as a unified control plane for consistent security policies, faster performance, and load balancing for your AWS S3 or EC2 deployment.

Is Cloudflare an API gateway?

At Cloudflare, we know APIs make the world go around. That is why we make our massive global network your API gateway. With API discovery, integrated API management and analytics, and layered API defenses, Cloudflare ensures APIs drive business success like never before.

What are the correct steps to deploy an API gateway in Amazon?

Sign in to the API Gateway console at https://console.aws.amazon.com/apigateway . In the APIs navigation pane, choose the API you want to deploy. In the Resources navigation pane, choose Actions. From the Actions drop-down menu, choose Deploy API.


1 Answers

Most likely you have your SSL mode on Cloudflare set to "Flexible", which doesn't use https to connect to the origin server. API gateway tries to redirect non-secure requests, so you have a redirect loop.

Set your SSL mode to "Full" and you should be good to go! You can do this on the "Crypto" tab of the Cloudflare dashboard.

like image 189
BonsaiOak Avatar answered Oct 19 '22 22:10

BonsaiOak