Skip to content

Instantly share code, notes, and snippets.

@kulp
Created March 6, 2016 02:59
Show Gist options
  • Save kulp/7c3c33e8b8b70252efe6 to your computer and use it in GitHub Desktop.
Save kulp/7c3c33e8b8b70252efe6 to your computer and use it in GitHub Desktop.
Update AWS Route 53 DNS entry with current IP
#!/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