Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Have Route 53 point to an instance instead of an IP or CNAME?

We're using Route 53 DNS to point to an EC2 instance. Is there any way to get Route 53 to point to the instance directly, instead of to an Elastic IP or CNAME?

I have multiple reasons for this:

  1. I don't want to burn an IP.

  2. CNAMEs are unreliable, because if an instance goes down and comes back up, the full name, ec2-X-X-X-X.compute-1.amazonaws.com, will change.

  3. In the future, I need to spin up instances programmatically and address them with a subdomain, and I see no easy way to do this with either elastic IPs or CNAMEs.

What's the best approach?

like image 740
ccleve Avatar asked Apr 10 '12 21:04

ccleve


People also ask

What is the difference between CNAME and A record in Route 53?

To clarify my question, the difference between CNAME and A record in a traditional NameServer is that only CNAME can be used to point to a different subdomain and A record must point to a valid IP address. Since the AWS Route53 allows you to do use a subdomain with either A Rec or CNAME ..

What is AWS Route 53 CNAME?

CNAME support Route 53 follows the pointer in an alias record only if the record type matches. To create an alias record for a CNAME record, the alias target must resolve to a CNAME value. Even if you create an invalid CNAME(ALIAS) record, Route 53 can't resolve the IP address of the endpoint.


2 Answers

I wrote my own solution to this problem since I was unhappy with other approaches that were presented here. Using Amazon CLI tools is nice, but they IMHO tend to be slower than direct API calls using other Amazon API libraries (Ruby for example).

Here's a link to my AWS Route53 DNS instance update Gist. It contains an IAM policy and a Ruby script. You should create a new user in IAM panel, update it with the attached policy (with your zone id in it) and set the credentials and parameters in the Ruby script. First parameter is the hostname alias for your instance in your hosted zone. Instance's private hostname is aliased to <hostname>.<domain> and instance's public hostname is aliased to <hostname>-public.<domain>

UPDATE: Here's a link to AWS Route53 DNS instance update init.d script registering hostnames when instance boots. Here's another one if want to use AWS Route53 DNS load-balancing in similar fashion.

like image 73
adamkonrad Avatar answered Oct 07 '22 00:10

adamkonrad


If you stick to using route53, you can make a script that updates the CNAME record for that instance everytime it reboots.

see this -> http://cantina.co/automated-dns-for-aws-instances-using-route-53/ (disclosure, i did not create this, though i used it as a jumping point for a similar situation)

better yet, because you mentioned being able to spin up instances programmatically, this approach should guide you to that end.

see also -> http://docs.pythonboto.org/en/latest/index.html

like image 43
gabriel Avatar answered Oct 06 '22 23:10

gabriel