Instantly share code, notes, and snippets.

Embed
What would you like to do?
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