Using multiple ELBs with Cloudflare DNS

If you have an autoscaling app on EC2, you need an ELB to distribute traffic. And if you don’t trust in ELB to be HA, you need at least 2 of them. The issue is that ELBs don’t have statis IPs, they can only be referenced with CNAME. That limits your DNS hosting option to just Route53, because apex record can’t be CNAMEd. But what if you (for some reason) don’t want to?

Fortunately, there’s a number of providers that violate RFC and do DNS flattening for you, even if you put CNAME at apex.

But.

Even then, (at least) Cloudflare won’t allow you to create round-robin CNAMEs. So you’re still stuck with one ELB.

Here’s the trick:

  1. Register a special “service” domain
  2. Delegate it to Route53
  3. Create a few equally weigthed record sets CNAMEd to ELBs (say, lb.service-domain.net)
  4. On Cloudflare, CNAME the required record (apex or not) to the service lb record (lb.service-domain.net)
  5. Bingo! Now you have ELBs round-robined, and your main domain is still on Cloudflare.

That’s actually a tip from a friend.

Comments