-
Notifications
You must be signed in to change notification settings - Fork 0
/
aws_cli_route53_test-json.sh
60 lines (50 loc) · 1.38 KB
/
aws_cli_route53_test-json.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
#!/bin/bash
#filename: aws_cli_route53_test-json.sh
#description: automatically registers a domain and ptr record in route53 for AWS using json files.
#author: Theodore Knab
HOSTED_ZONE_ID="XXXXXXXX1"
REVERSE_ZONE_ID="XXXXXXX2"
DOMAIN="myexample.com"
AWS_REGION=us-east-1
hostname="myhostname"
PRIV_IPV4=$(curl -s http://169.254.169.254/latest/meta-data/local-ipv4)
IPBRIF=$(curl -s http://169.254.169.254/latest/meta-data/local-ipv4 | awk -F "." '{print $4"." $3}')
ARPA="$IPBRIF.128.10.in-addr.arpa."
revfile="rev_file.json"
dnsfile="dns_file.json"
#json for dns record
cat > $dnsfile << EOF
{
"Comment": "R53DNS.sh created A for $hostname.$DOMAIN",
"Changes": [{
"Action": "UPSERT",
"ResourceRecordSet": {
"Name": "$hostname.$DOMAIN." ,
"Type": "A",
"TTL" : 300,
"ResourceRecords": [{
"Value": "$PRIV_IPV4"
}]
}
}]
}
EOF
aws route53 change-resource-record-sets --hosted-zone-id $HOSTED_ZONE_ID --change-batch file://$dnsfile
#json for PTR record
cat > $revfile << EOF
{
"Comment": "R53DNS.sh created PTR for $hostname.$DOMAIN",
"Changes": [{
"Action": "UPSERT",
"ResourceRecordSet": {
"Name": "$ARPA" ,
"Type": "PTR",
"TTL" : 300,
"ResourceRecords": [{
"Value": "$hostname.$DOMAIN."
}]
}
}]
}
EOF
aws route53 change-resource-record-sets --hosted-zone-id $REVERSE_ZONE_ID --change-batch file://$revfile