Last active
October 14, 2017 15:43
-
-
Save na0AaooQ/02c84873f7696535f448 to your computer and use it in GitHub Desktop.
AWS Route53 ゾーン作成とDNSレコード追加コマンドメモ ref: http://qiita.com/na0AaooQ/items/d5bb618b7922233ce665
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
{ | |
"Version": "2012-10-17", | |
"Statement":[ | |
{ | |
"Effect":"Allow", | |
"Action":["route53:CreateHostedZone"], | |
"Resource":"*" | |
}, | |
{ | |
"Effect":"Allow", | |
"Action":["route53:DeleteHostedZone"], | |
"Resource":"arn:aws:route53:::change/*" | |
}, | |
{ | |
"Effect":"Allow", | |
"Action":["route53:GetChange"], | |
"Resource":"arn:aws:route53:::change/*" | |
} | |
] | |
} |
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
$ sudo curl -o /usr/bin/jq http://stedolan.github.io/jq/download/linux64/jq && sudo chmod +x /usr/bin/jq |
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
$ aws route53 change-resource-record-sets --hosted-zone-id ${R53_ZONE_ID} --change-batch file:///tmp/create_dns_recordset.json |
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
{ | |
"ChangeInfo": { | |
"Status": "PENDING", | |
"SubmittedAt": "2014-12-23T15:35:24.690Z", | |
"Id": "/change/**************" | |
} | |
} |
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
$ aws route53 list-resource-record-sets --hosted-zone-id ${R53_ZONE_ID} |
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
{ | |
"ResourceRecordSets": [ | |
{ | |
"ResourceRecords": [ | |
{ | |
"Value": "ns-617.awsdns-13.net." | |
}, | |
{ | |
"Value": "ns-497.awsdns-62.com." | |
}, | |
{ | |
"Value": "ns-1868.awsdns-41.co.uk." | |
}, | |
{ | |
"Value": "ns-1243.awsdns-27.org." | |
} | |
], | |
"Type": "NS", | |
"Name": "example.com.", | |
"TTL": 172800 | |
}, | |
{ | |
"ResourceRecords": [ | |
{ | |
"Value": "ns-617.awsdns-13.net. awsdns-hostmaster.amazon.com. 1 7200 900 1209600 86400" | |
} | |
], | |
"Type": "SOA", | |
"Name": "example.com.", | |
"TTL": 900 | |
}, | |
{ | |
"ResourceRecords": [ | |
{ | |
"Value": "198.51.100.10" | |
} | |
], | |
"Type": "A", | |
"Name": "server-001.example.com.", | |
"TTL": 1200 | |
}, | |
{ | |
"ResourceRecords": [ | |
{ | |
"Value": "198.51.100.11" | |
} | |
], | |
"Type": "A", | |
"Name": "server-002.example.com.", | |
"TTL": 1200 | |
}, | |
{ | |
"ResourceRecords": [ | |
{ | |
"Value": "server-001.example.com." | |
} | |
], | |
"Type": "CNAME", | |
"Name": "server-cname.example.com.", | |
"TTL": 3600 | |
} | |
] | |
} |
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
$ dig +noall +ans +norec server-001.example.com. @ns-497.awsdns-62.com | |
server-001.example.com. 1200 IN A 198.51.100.10 | |
$ |
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
$ dig +noall +ans +norec server-002.example.com. @ns-497.awsdns-62.com | |
server-002.example.com. 1200 IN A 198.51.100.11 | |
$ |
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
$ dig +noall +ans +norec server-cname.example.com. @ns-497.awsdns-62.com | |
server-cname.example.com. 3600 IN CNAME server-001.example.com. | |
server-001.example.com. 1200 IN A 198.51.100.10 | |
$ |
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
$ cp /tmp/create_dns_recordset.json /tmp/delete_dns_recordset.json | |
$ sed -i "s/CREATE/DELETE/g" /tmp/delete_dns_recordset.json | |
$ |
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
$ cat /tmp/delete_dns_recordset.json | wc -l | |
43 | |
$ cat /tmp/delete_dns_recordset.json | jq . | wc -l | |
43 | |
$ |
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
$ aws route53 change-resource-record-sets --hosted-zone-id ${R53_ZONE_ID} --change-batch file:///tmp/delete_dns_recordset.json | |
{ | |
"ChangeInfo": { | |
"Status": "PENDING", | |
"SubmittedAt": "2014-12-23T15:53:55.293Z", | |
"Id": "/change/C3BMEQ2NS76GSU" | |
} | |
} | |
$ |
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
$ R53_ZONE_NAME="example.com" | |
$ R53_ZONE_COMMENT="exampledomain" | |
$ | |
$ aws route53 create-hosted-zone --name ${R53_ZONE_NAME} --caller-reference `date +%Y-%m-%d_%H-%M-%S` --hosted-zone-config Comment="${R53_ZONE_COMMENT}" |
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
$ aws route53 list-resource-record-sets --hosted-zone-id ${R53_ZONE_ID} |
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
$ aws route53 delete-hosted-zone --id=${R53_ZONE_ID} | |
{ | |
"ChangeInfo": { | |
"Status": "PENDING", | |
"SubmittedAt": "2014-12-23T16:00:20.320Z", | |
"Id": "/change/*************" | |
} | |
} | |
$ |
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
$ aws route53 list-hosted-zones |
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
$ aws route53 list-hosted-zones |
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
{ | |
"HostedZones": [ | |
{ | |
(途中省略) | |
}, | |
{ | |
"ResourceRecordSetCount": 2, | |
"CallerReference": "2014-12-23_23-47-30", | |
"Config": { | |
"Comment": "exampledomain", | |
"PrivateZone": false | |
}, | |
"Id": "/hostedzone/**************", | |
"Name": "example.com." | |
} | |
] | |
} | |
$ |
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
$ R53_ZONE_ID=`aws route53 list-hosted-zones | jq --arg zone_name "${R53_ZONE_NAME}." -r '.HostedZones[]|select(.Name == $zone_name)|.Id' | sed 's/\/hostedzone\///'` | |
$ |
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
$ echo ${R53_ZONE_ID} | |
Z************* | |
$ |
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
cat <<EOT > /tmp/create_dns_recordset.json | |
{ | |
"Changes": [ | |
{ | |
"Action": "CREATE", | |
"ResourceRecordSet": { | |
"Name": "server-001.example.com.", | |
"Type": "A", | |
"TTL": 1200, | |
"ResourceRecords": [ | |
{ | |
"Value": "198.51.100.10" | |
} | |
] | |
} | |
}, | |
{ | |
"Action": "CREATE", | |
"ResourceRecordSet": { | |
"Name": "server-002.example.com.", | |
"Type": "A", | |
"TTL": 1200, | |
"ResourceRecords": [ | |
{ | |
"Value": "198.51.100.11" | |
} | |
] | |
} | |
}, | |
{ | |
"Action": "CREATE", | |
"ResourceRecordSet": { | |
"Name": "server-cname.example.com.", | |
"Type": "CNAME", | |
"TTL": 3600, | |
"ResourceRecords": [ | |
{ | |
"Value": "server-001.example.com." | |
} | |
] | |
} | |
} | |
] | |
} | |
EOT |
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
$ cat /tmp/create_dns_recordset.json | wc -l | |
43 | |
$ cat /tmp/create_dns_recordset.json | jq . | wc -l | |
43 | |
$ |
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
$ sed -i -e '1,1d' /tmp/create_dns_recordset.json | |
$ | |
$ cat /tmp/create_dns_recordset.json | wc -l | |
42 | |
$ cat /tmp/create_dns_recordset.json | jq . | wc -l | |
parse error: Expected string key before ':' at line 1, column 12 | |
1 | |
$ |
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
{ | |
"Version": "2012-10-17", | |
"Statement":[ | |
{ | |
"Effect":"Allow", | |
"Action":["route53:CreateHostedZone"], | |
"Resource":"*" | |
}, | |
{ | |
"Effect":"Allow", | |
"Action":["route53:DeleteHostedZone"], | |
"Resource":"arn:aws:route53:::change/*" | |
}, | |
{ | |
"Effect":"Allow", | |
"Action":["route53:GetChange"], | |
"Resource":"arn:aws:route53:::change/*" | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment