-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathroute53.sh
66 lines (56 loc) · 1.78 KB
/
route53.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/bin/bash
# Creates a Route 53 ALIAS in the zone specified by `zoneId` for the
# ELB specified by `elbName`. This returns 30 seconds after the update
# returns with status "INSYNC".
# Exit if anything fails
set -e
if [ $# -lt 2 ]; then
echo "USAGE: route53 <zoneId> <elbName>"
exit 1
fi
zone=$1
elbName=$2
# File to contain our provisioning settings for Route 53
rel_json=./route53.json
abs_json=$(cd $(dirname "${rel_json}") && pwd -P)/$(basename "${rel_json}")
# Describe the ELB to get the zone ID and DNS
aws elb describe-load-balancers --load-balancer-name ${elbName} > elb.json
elbZone=`./jq --raw-output '.LoadBalancerDescriptions[0].CanonicalHostedZoneNameID' elb.json`
elbDns=`./jq --raw-output '.LoadBalancerDescriptions[0].DNSName' elb.json`
# Write our command for AWS Route 53 to a json file
cat > ${rel_json} <<EOF
{
"Comment": "Updated via route53.sh",
"Changes": [
{
"Action": "UPSERT",
"ResourceRecordSet": {
"Name": "proseand.co.nz.",
"Type": "A",
"AliasTarget": {
"HostedZoneId": "${elbZone}",
"DNSName": "${elbDns}",
"EvaluateTargetHealth": false
}
}
}
]
}
EOF
# Update the record set
aws route53 change-resource-record-sets \
--hosted-zone-id ${zone} \
--change-batch file://${abs_json} \
> ./route53-change.json
# Get the ID for our change request
changeId=`./jq --raw-output '.ChangeInfo.Id' ./route53-change.json`
status=PENDING
# Poll the status of our change request until it is "INSYNC"
while [ "${status}" = "PENDING" ]; do
sleep 5
aws route53 get-change --id ${changeId} > ./route53-change.json
status=`./jq --raw-output '.ChangeInfo.Status' ./route53-change.json`
echo "Route53 ALIAS status: ${status}"
done
# Wait another 30 seconds while the Internets update
sleep 30