Skip to content

Instantly share code, notes, and snippets.

@doi-t
Last active June 6, 2019 21:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save doi-t/0ebdbdd6ed8a9e27ca563aed7a474899 to your computer and use it in GitHub Desktop.
Save doi-t/0ebdbdd6ed8a9e27ca563aed7a474899 to your computer and use it in GitHub Desktop.
Change an A record of a domain managed by AWS Route53.
#!/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