Last active
May 17, 2017 00:11
-
-
Save xleliberty/65e2764aa643a5b1b61715460768f047 to your computer and use it in GitHub Desktop.
update route53 record from instance meta datas
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 | |
MYDOMAIN="mydomain.com" | |
RECORD="myrecord.${MYDOMAIN}." | |
MYIP=$(curl -o- -s http://169.254.169.254/latest/meta-data/public-ipv4) | |
HOSTED_ZONE_ID=$(aws route53 list-hosted-zones-by-name --dns-name $MYDOMAIN | jq -r '.HostedZones[0].Id' | sed "s/\/hostedzone\///") | |
echo "Hosted zone being modified: $HOSTED_ZONE_ID" | |
INPUT_JSON=$(cat <<EOT | |
{ | |
"Comment": "Update the A record set", | |
"Changes": [ | |
{ | |
"Action": "UPSERT", | |
"ResourceRecordSet": { | |
"Name": "${RECORD}", | |
"Type": "A", | |
"TTL": 300, | |
"ResourceRecords": [ | |
{ | |
"Value": "${MYIP}" | |
} | |
] | |
} | |
} | |
] | |
} | |
EOT | |
) | |
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