From http://ternarylabs.com/2010/09/15/automatically-configure-hostname-for-new-ec2-instances/