Skip to content

Instantly share code, notes, and snippets.

@xleliberty
Last active May 17, 2017 00:11
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 xleliberty/65e2764aa643a5b1b61715460768f047 to your computer and use it in GitHub Desktop.
Save xleliberty/65e2764aa643a5b1b61715460768f047 to your computer and use it in GitHub Desktop.
update route53 record from instance meta datas
#!/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