Skip to content

Instantly share code, notes, and snippets.

@z0ph
Last active October 27, 2018 17:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save z0ph/bd3cffd45a3051989e64161898242e54 to your computer and use it in GitHub Desktop.
Save z0ph/bd3cffd45a3051989e64161898242e54 to your computer and use it in GitHub Desktop.
{
"Comment": "Update the A record set",
"Changes": [
{
"Action": "UPSERT",
"ResourceRecordSet": {
"Name": "MY_DNS_RECORD_NAME",
"Type": "A",
"TTL": 60,
"ResourceRecords": [
{
"Value": "127.0.0.1"
}
]
}
}
]
}
#!/bin/sh
if [ -z "$1" ]; then
echo "IP not given...trying EC2 metadata...";
IP=$( curl -s http://169.254.169.254/latest/meta-data/public-ipv4 )
else
IP="$1"
fi
echo "IP to update: $IP"
HOSTED_ZONE_ID=$( aws route53 list-hosted-zones-by-name | grep -B 1 -e "YOUR_PARENT_DOMAIN_NAME" | sed 's/.*hostedzone\/\([A-Za-z0-9]*\)\".*/\1/' | head -n 1 )
echo "Hosted zone being modified: $HOSTED_ZONE_ID"
INPUT_JSON=$( cat /home/ec2-user/update53/update-route53-A.json | sed "s/127\.0\.0\.1/$IP/" )
# http://docs.aws.amazon.com/cli/latest/reference/route53/change-resource-record-sets.html
# We want to use the string variable command so put the file contents (batch-changes file) in the following JSON
INPUT_JSON="{ \"ChangeBatch\": $INPUT_JSON }"
aws route53 change-resource-record-sets --hosted-zone-id "$HOSTED_ZONE_ID" --cli-input-json "$INPUT_JSON"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment