Last active
November 13, 2016 17:33
-
-
Save rbenigno/c534dd63d09668fb4c7042b4baa94308 to your computer and use it in GitHub Desktop.
Update Route53 CNAME for an ec2 instance, from that instance
This file contains 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 | |
# Ubuntu: Place this script in /var/lib/cloud/scripts/per-boot | |
HOST_CNAME=<CNAME to Update> | |
HOSTED_ZONE_ID=<Route53 Zone ID> | |
INSTANCE_ID=$(ec2metadata | grep 'instance-id:' | cut -d ' ' -f 2) | |
PUBLIC_HOSTNAME=$(ec2metadata | grep 'public-hostname:' | cut -d ' ' -f 2) | |
read -d '' DNS_CHANGE_JSON <<-_EOF_ | |
{ | |
"Comment": "Update host", | |
"Changes": [ | |
{ | |
"Action": "UPSERT", | |
"ResourceRecordSet": { | |
"Name": "$HOST_CNAME", | |
"Type": "CNAME", | |
"TTL": 60, | |
"ResourceRecords": [ | |
{ | |
"Value": "$PUBLIC_HOSTNAME" | |
} | |
] | |
} | |
} | |
] | |
} | |
_EOF_ | |
aws route53 change-resource-record-sets --hosted-zone-id "$HOSTED_ZONE_ID" --change-batch "$DNS_CHANGE_JSON" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment