Michael Yagudaev
Michael Yagudaev

Reputation: 6129

Wildcard CNAME and Wildcard MX Record

We are in the process of migrating from Engine Yard to Heorku. The struggle is with the Heroku's use of CNAME records.

I would like to setup the following records on Route53 (switching away to another DNS provider is a last resort, I would prefer to keep things on AWS as we have a lot of other services we use there).

CNAME www.example.com corporate-site.wpengine.com
CNAME *.example.com   example.herokuapp.com
MX    *.example.com   1 mailgun.org
MX      example.com   1 aspmx.l.google.com

The idea is that someone can go to demo.example.com and get served the heroku application. They can also email [email protected] and this will go to a normal gmail inbox. But when they send an email to [email protected] the email is processed by MailGun. For example, Craiglist uses this approach to reply to posts.

The DNS setup above is not valid for Route53. That's because CNAME records names must be unique across all record types. This is not a problem however with A records, which is the way it was setup before.

Note that a simple 301 redirect would not do here. We want demo.example.com to always point to demo.example.com. Each subdomain is used by the heroku application to determine the account to load (or if you think of the Craiglist example, a seperate geographic region, we don't want to redirect to just one region and have many regions we create dynamically).

What is the recommended way to solve this problem?

Upvotes: 1

Views: 3100

Answers (2)

Michael Yagudaev
Michael Yagudaev

Reputation: 6129

After talking to Heroku support, Mailgun support and many of you. It became apparent this could not be done with Route53.

To achieve this you need to either use an ALIAS record or an ANAME record. Route53 supports aliasing only to endpoints inside your own AWS account. Therefore, it is not doable with their service as of yet.

We switched to DNSMadeEasy which was recommended by Heroku and have very good performance. I find the interface very unintuitive, but you only need to do it once. All I needed to do was create a wildcard ANAME record pointing to heroku and everything else worked fine.

I do recommend you checkout DNSimple, their interface is great and I love their service. They are not as established as DNSMadeSimple, but they are certainly more friendly to use. I hope to one day use their service.

Upvotes: 0

Rico
Rico

Reputation: 61669

I found that Route53 supports Alias records, but not outside of their own network

The workaround is here:

https://devcenter.heroku.com/articles/route-53#naked-root-domain

Basically:

  1. Create an S3 bucket called: yourdomain.com and make it redirect to www.yourdomain.com
  2. On Route 53, create an A record alias to point to your bucket for the Naked/root domain of yourdomain.com
  3. Finally, create a CNAME record for www.yourdomain.com to point to yourapp.herokuapp.com

That should do it.

Upvotes: 2

Related Questions