Skip to content

Instantly share code, notes, and snippets.

@TonyFNZ
Created October 9, 2016 20:36
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save TonyFNZ/ba22dcb7d74260c88bbf1d17741c4c56 to your computer and use it in GitHub Desktop.
Save TonyFNZ/ba22dcb7d74260c88bbf1d17741c4c56 to your computer and use it in GitHub Desktop.
Script to update Route53 with the current public IP of an instance
#!/bin/bash
hosted_zone_id="<your Route53 hosted zone id>"
domain_name="<your domain name>"
# Abort script on any errors
set -e
# Get new IP address
ip_address=`curl http://169.254.169.254/latest/meta-data/public-ipv4`
# Build temporary file
cat > ./dnsupdate.json <<EOF
{
"Changes": [
{
"Action": "UPSERT",
"ResourceRecordSet": {
"Name": "$domain_name",
"Type": "A",
"TTL": 300,
"ResourceRecords": [
{
"Value": "$ip_address"
}
]
}
}
]
}
EOF
# Call Route53 to update DNS
aws route53 change-resource-record-sets --hosted-zone-id $hosted_zone_id --change-batch file://./dnsupdate.json
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment