Skip to content

Instantly share code, notes, and snippets.

@zircote
Created November 10, 2012 22:16
Show Gist options
  • Save zircote/4052735 to your computer and use it in GitHub Desktop.
Save zircote/4052735 to your computer and use it in GitHub Desktop.
Grabs the hostname from the Name Meta-tag, if it has the zone in it, it is striped and added to route53. If it is on a VPC it CNAMES the private IP otherwise the public hostname.
#!/bin/bash
ZONE="my.route53-dnszone.com"
test_local="$(curl --write-out %{http_code} --silent --output \
/dev/null http://169.254.169.254/latest/meta-data/public-hostname)"
if [ "200" = "$test_local" ]; then
CNAME="$(curl -s http://169.254.169.254/latest/meta-data/public-hostname)"
else
CNAME="$(curl -s http://169.254.169.254/latest/meta-data/local-ipv4)"
fi
HOSTNAME="$(ec2-describe-tags \
-O ${AWS_ACCESS_KEY_ID} \
-W ${AWS_SECRET_ACCESS_KEY} \
--filter "resource-type=instance" \
--filter "resource-id=$(ec2-metadata -i | cut -d ' ' -f2)" \
--filter "key=Name" | cut -f5)"
cli53 rrcreate -r ${ZONE} ${HOSTNAME/.$ZONE/} CNAME ${CNAME}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment