3

Looking for a "best practice" answer to managing externally-addressable hosts using the combination of Amazon EC2 and Amazon Route 53, without using Elastic IPs for each host. In my scenario I will have 30+ hosts that need to be accessible from outside EC2, so directly using internal DNS will not work.

In the past, I have addressed hosts by assigning an elastic IP to that host (let's say, 55.55.55.55) and then creating an associated A record. For example, let's say I want to create "ec2-corp01.mydomain.com" I might do:

ec2-corp01.mydomain.com.     A     55.55.55.55     300

Then on that EC2 instance, I would assign the Elastic IP of 55.55.55.55, and everything works fine. Of course, to make this work, I need to have one Elastic IP per instance, which is something I'd like to avoid if possible; I'd like the infrastructure to be more dynamic.

So my thought is to try something like:

  • Create a script that queries the internal EC2 tools to determine an instance's private hostname

  • On instance boot, call that script to determine its hostname, and then using the command-line Route 53 interface to find and update that hostname to its current internal hostname

  • Since the host will have a relatively low TTL (let's say 300 as above, or 5 minutes) it should take effect pretty quickly

Is this a good idea? Is there a better or more widely accepted way to handle it?

If it IS a good idea, what type of record should I be creating? A CNAME that points to the internal host, like ec2-55-55-55-55.compute-1.amazonaws.com? Is an A record better or worse?

Thanks!

2 Answers 2

2

Automate it. Just make part of the script that creates the new instance lookup the public IP (or the public name) by it's instance ID (you get the instance ID when you call ec2-run-instances; just keep calling ec2-describe-instances <instanceID> until you get an entry in the right field), then modify your DNS (it can be Route53, but doesn't have to be) to contain either a CNAME or A record with the data you obtained.

There might be some Route53 magic that'll do the trick, too, like there is with ELB, but I've not come across it.

1

For an A record; you would indeed need an Elastic IP for each instance. What I would do in such a case is as stated; assign each instance a CNAME using the AWS API for Route 53. If this is for something also like load balancing, i'd recommend using AWS Elastic Load Balancing service which will automate a lot of this (look into it some more to see if it fits your requirements as it is an additional fee).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .