This Time Self-Hosted
dark mode light mode Search

Amazon EC2: stable hostnames, for free, really

In my current line of work, dealing with Amazon’s “Elastic” Computer Cloud, I had to cope with the problem of getting a stable hostname for a “master” instance when dealing with “slaves”. I was appalled by the fact that Amazon does not provide a way to assign a “role” or “class name” to their instances, so to have them recognized from within their network.

When I was pointed out at multiple documentation showing how to achieve that feature, I knew that the problem wasn’t that Amazon failed to to think that through, but rather that they are most likely trying to get more money out of the users with these need. The common suggestion to solve the need to identify a particular instance, between executions, is to use their “Elastic IP” feature (which – like many other things they call “Elastic” – is not really elastic at all).

The idea behind this solution is that by assigning a public IPv4 (and keep in mind this is a precious resource nowadays) to the instance, you can pick up the reverse DNS for it (for instance 184.73.246.248 will reverse-resolve to ec2-184-73-246-248.compute-1.amazonaws.com), and use that in your intra-EC2 requests… once using EC2’s own nameservers, ec2-184-73-246-248.compute-1.amazonaws.com will resolve to the (dynamic) internal IP address (10.0.0.0/8) of the instance the IP was assigned to.

All fine and dandy, and this can be set up cleanly with Rudy as well. The problem here is… the IP is not free. Oh yes, the documentation will try to tell you that you won’t have to pay for it… as long as you use it. But it’s definitely not free, especially during the development phase of a project. As long as the address is assigned to an instance, you won’t pay for the Elastic IP service (but you will pay for the running instance); if you don’t have an assigned instance, you’ll end up paying $2.4 per day for the IP address to be reserved.

This is definitely one of the cases where Amazon’s limitation seem totally artificial to get you more money, as much money as they can get from you. D’oh!

What is my solution to this problem? It’s very simple: net-misc/ddclient. The IP address you’re looking for is the one, inside the instance, that is assigned to the eth0 interface. Just tell ddclient to fetch the address and use it on a classic DynDNS (or similar) hostname service. It doesn’t matter that you’re feeding them a local IP address (in the 10.0.0.0/8 range); you won’t be able to use the same hostname for external and internal dealing, but it’ll definitely cost you less.

Comments 6
  1. Hmm… Have You tried some kind of solution using avahi/zeroconf/bonjour?(Just add some kind of custom service on the “master” machine and make slaves discover it using avahi)I do not remember now, but afair EC2 allows you to do some kind of internal network, so everything shouldn’t go outside if You don’t want to…

  2. The bonjour protocol relies on broadcast messages to be passed around, which I *hope* EC2 is not passing around to begin with… so that excludes the use of Avahi in this situation.

  3. mi fa piacere sapere che qualche altro italiano lavori su ec2 :)buon lavoro!

  4. This doesn’t work.If i get the IP of eth0 and trying to reconnect via Remote Desktop, i ONLY can connect to the Public DNS, but not to the IP.Can you tell me, how it works? I tried it in Windows 2008 Server with CMD > IPCONFIG.

  5. What are you talking about? It’s $0.01 per hour for an unattached IP address. That’s a grand total of $0.24 a day, not $2.40 a day. For a month, that adds up to all of $7.20.

Leave a Reply to JabbasCancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.