Wednesday, December 29, 2010

heading down route 53, dynamic dns for short $

Been hacking about with route53 for a day or so to replace a dynamic dns service. So far so good. The HTTP/XML stuff is a bit tricky, is a great reference example, but needed something to be a bit more easy to script around. I was about to bust out some extreme perl XML::Twig parsing action, but the folks over @ boto already have the core part of this nailed! Plus they have some lovely extra stuff in there also for cli based cloud mngt:

Remember to install the python setup tools if you don't have them already 10.04 didn't and I missed the error in the boto build caused me a small amount of churn by not paying attention:
/usr/lib/python2.6/distutils/ UserWarning: Unknown distribution option: 'install_requires'

Here's the missing piece:
root@shuttle:/home/jcuff# apt-get install python-setuptools

Now the install is cake:
root@shuttle:/home/jcuff# git clone git://
root@shuttle:/home/jcuff# python build
root@shuttle:/home/jcuff# sudo python install

Barnaby Gray has a neato little script here that you can use in conjunction with boto and python dns tools:

root@shuttle:/home/jcuff# git clone

As I mentioned, it has a dep on dnspython (oh and easy_install is awesome for python mod installs!):
root@shuttle:/home/jcuff# easy_install dnspython

Now we are all set with I've used an example dns and config below to show function only:
root@shuttle:/home/jcuff# ./ list
- CallerReference: jamesdotcuff.1
Comment: Migrate an existing domain to Route 53
Id: /hostedzone/Z1PZZZZDBXO12345

Even has a very swish bind interface for import and export to the old classic DNS services we are used to, here is an example with an aws A record:
root@shuttle:/home/jcuff# ./ export
@ 172800 IN NS
@ 172800 IN NS
@ 172800 IN NS
@ 172800 IN NS
@ 900 IN SOA 1 7200 900 1209600 86400
aws 600 IN A

Interesting how big the AWS ninjas are planning their dns install to be, did you see those host names... ns-xxxx huge eh? :-).

Anyway, now to wrap this in a simple ifconfig script for those on dhcp cable modems and tada - "free" full bore dynamic dns(*):

first delete the old record:
root@shuttle:/home/jcuff# ./ rrdelete aws A

and update your dns with the new one for your new IP address that your dsl/cable provider has given you. The script is also smart and allows you a TTL with the -x option. Neat!
root@shuttle:/home/jcuff# ./ rrcreate -x 600 aws A

and tada! we are basically good to go. I'm sure that AWS will have an "update record" api soon so the whole delete / create thing for rr sets will not be an issue, it's not a big deal breaker - just two calls rather than one. Oh hang on there cowboy! What's this? Looks like Barnaby has thought of everything, there is a --replace option, and a --wait to hang on until the sync is complete. Done, and done:
root@shuttle:/home/jcuff# ./ rrcreate -x 600 aws A --replace --wait
Waiting for change to sync.............................completed
Status: INSYNC
SubmittedAt: 2010-12-29T19:01:52.980Z

root@shuttle:/home/jcuff# host has address

Now that to me is an epic one liner!

Albeit folks always find something to complain about, this stuff is just what I needed. Also a lovely example of wicked fast development in the community. So my personal thanks to Barnaby and all the boto folks, no need for me to give birth to yet another dodgy perl script ;-)

Keep at it AWS ninjas, where ever you all may be!

(*) well 1 buck a month per zone is not so bad ;-)

[any opinions here are all mine, and have absolutely nothing to do with my employer]
(c) 2011 James Cuff