Last active
June 6, 2019 21:59
-
-
Save doi-t/0ebdbdd6ed8a9e27ca563aed7a474899 to your computer and use it in GitHub Desktop.
Change an A record of a domain managed by AWS Route53.
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/bash | |
set -ex | |
[ $# -ne 3 ] && echo "Usage $0 <your zone id> <your domain> <your ip>" && exit 1 | |
MY_ZONE_ID=$1 | |
MY_DOMAIN=$2 | |
MY_IP=$3 | |
TMPFILE=$(mktemp /tmp/${MY_DOMAIN}_upsert_${MY_IP}.XXXXXX) | |
cat <<-EOF > ${TMPFILE} | |
{ | |
"Comment": "Update IP via awscli", | |
"Changes": [ | |
{ | |
"Action": "UPSERT", | |
"ResourceRecordSet": { | |
"Name": "${MY_DOMAIN}", | |
"Type": "A", | |
"TTL": 30, | |
"ResourceRecords": [ | |
{ | |
"Value": "${MY_IP}" | |
} | |
] | |
} | |
} | |
] | |
} | |
EOF | |
aws route53 change-resource-record-sets --hosted-zone-id /hostedzone/${MY_ZONE_ID} --change-batch file://${TMPFILE} | |
aws route53 list-resource-record-sets --hosted-zone-id /hostedzone/${MY_ZONE_ID} | jq ".[][] | select(.Name==\"${MY_DOMAIN}\")" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment