Created
March 6, 2016 02:59
-
-
Save kulp/7c3c33e8b8b70252efe6 to your computer and use it in GitHub Desktop.
Update AWS Route 53 DNS entry with current IP
This file contains hidden or 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/sh -e | |
HOSTED_ZONE_IP=/hostedzone/CHANGEME | |
DOMAIN=CHANGEME | |
TTL=300 | |
my_ip=$HOME/.my_ip | |
IP=$(dig +short myip.opendns.com @resolver1.opendns.com) | |
if [ "$IP" = "$(cat $my_ip)" ] | |
then | |
exit 0 | |
fi | |
json=$(cat <<EOF | |
{ | |
"Changes": [ | |
{ | |
"Action": "UPSERT", | |
"ResourceRecordSet": { | |
"Name": "$DOMAIN", | |
"Type": "A", | |
"TTL": $TTL, | |
"ResourceRecords": [ | |
{ | |
"Value": "$IP" | |
} | |
] | |
} | |
} | |
] | |
} | |
EOF | |
) | |
aws route53 change-resource-record-sets --hosted-zone-id $HOSTED_ZONE_IP --change-batch "$json" | |
echo "$IP" > $my_ip |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment