-
-
Save dennissterzenbach/3dd89de85f28ea198ca61e745bb1a362 to your computer and use it in GitHub Desktop.
Script to update Route53 with the current public IP of an instance
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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