https://dev.classmethod.jp/articles/implement-route53-routing-for-begineer/
https://docs.aws.amazon.com/ja_jp/Route53/latest/DeveloperGuide/routing-policy.html
シンプルルーティング
加重ルーティング -> 指定した比率で複数のリソースにトラフィックをルーティング
位置情報ルーティング -> ユーザーの位置に基づいてトラフィックをルーティング
レイテンシールーティング -> より少ない往復時間で最良のレイテンシーを実現するリージョンにトラフィックをルーティング
フェイルオーバールーティング -> アクティブ/パッシブフェイルオーバーを構成する
複数値回答ルーティング -> ランダムに選ばれた最大 8 つの正常なレコードを使用して Route 53 が DNS クエリに応答する
前提:
下記リージョンのデフォルトのセキュリティグループでインバウンドHTTP (0.0.0.0/0)を許可
バージニア us-east-1 Virginia 192.0.2.11
パリ eu-west-3 Paris 192.0.2.12
-- 1. コマンド等のインストール
-- 1.1 aws cli version 2 インストール
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/install
aws --version
-- 1.2 jqインストール
sudo yum -y install jq
-- 2. EC2インスタンス作成
export AWS_DEFAULT_REGION=us-east-1
vim Virginia.sh
#!/bin/bash
yum -y update
yum -y install httpd
systemctl start httpd
systemctl enable httpd
systemctl status httpd
bash -c "echo Virginia > /var/www/html/index.html"
aws ec2 run-instances \
--image-id ami-0022f774911c1d690 \
--instance-type t3.nano \
--tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=Virginia}]' \
--user-data file://Virginia.sh
export AWS_DEFAULT_REGION=eu-west-3
vim Paris.sh
#!/bin/bash
yum -y update
yum -y install httpd
systemctl start httpd
systemctl enable httpd
systemctl status httpd
bash -c "echo Paris > /var/www/html/index.html"
aws ec2 run-instances \
--image-id ami-021d41cbdefc0c994 \
--instance-type t3.nano \
--tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=Paris}]' \
--user-data file://Paris.sh
export AWS_DEFAULT_REGION=ap-northeast-1
curl http://www.xxxxxxxxxxxx.link/index.html
curl http://192.0.2.11/index.html
curl http://192.0.2.12/index.html
-- 3. ホステッドゾーンの確認
aws route53 list-hosted-zones
-- 4. ヘルスチェックの作成
{
"IPAddress": "192.0.2.11",
"Port": 80,
"Type": "HTTP",
"ResourcePath": "/index.html",
"RequestInterval": 10,
"FailureThreshold": 2,
"MeasureLatency": false,
"Inverted": false,
"Disabled": false,
"EnableSNI": false
}
aws route53 create-health-check \
--caller-reference 0002 \
--health-check-config file://hc_Virginia.json
aws route53 change-tags-for-resource \
--resource-type healthcheck \
--resource-id 11111111-1111-1111-1111-111111111111 \
--add-tags Key=Name,Value=Virginia
{
"IPAddress": "192.0.2.12",
"Port": 80,
"Type": "HTTP",
"ResourcePath": "/index.html",
"RequestInterval": 10,
"FailureThreshold": 2,
"MeasureLatency": false,
"Inverted": false,
"Disabled": false,
"EnableSNI": false
}
aws route53 create-health-check \
--caller-reference 0012 \
--health-check-config file://hc_Paris.json
aws route53 change-tags-for-resource \
--resource-type healthcheck \
--resource-id 22222222-2222-2222-2222-222222222222 \
--add-tags Key=Name,Value=Paris
aws route53 list-health-checks
aws route53 get-health-check \
--health-check-id 11111111-1111-1111-1111-111111111111
aws route53 get-health-check \
--health-check-id 22222222-2222-2222-2222-222222222222
-- 5. シンプルルーティング
{
"Comment": "CREATE/DELETE/UPSERT a record ",
"Changes": [
{ "Action": "UPSERT",
"ResourceRecordSet": { "Name": "www.xxxxxxxxxxxx.link.",
"Type": "A",
"TTL": 10,
"ResourceRecords": [
{ "Value": "192.0.2.11" }
]
}
}
]
}
aws route53 change-resource-record-sets \
--hosted-zone-id 333333333333333333333 \
--change-batch file://a.json
aws route53 list-resource-record-sets \
--hosted-zone-id 333333333333333333333
-- 6. 加重ルーティング
{
"Comment": "CREATE/DELETE/UPSERT a record ",
"Changes": [
{ "Action": "UPSERT",
"ResourceRecordSet": { "Name": "www.xxxxxxxxxxxx.link.",
"Type": "A",
"SetIdentifier": "rec1",
"Weight": 80,
"TTL": 10,
"ResourceRecords": [
{ "Value": "192.0.2.11" }
]
}
},
{ "Action": "UPSERT",
"ResourceRecordSet": { "Name": "www.xxxxxxxxxxxx.link.",
"Type": "A",
"SetIdentifier": "rec2",
"Weight": 20,
"TTL": 10,
"ResourceRecords": [
{ "Value": "192.0.2.12" }
]
}
}
]
}
aws route53 change-resource-record-sets \
--hosted-zone-id 333333333333333333333 \
--change-batch file://a.json
aws route53 list-resource-record-sets \
--hosted-zone-id 333333333333333333333
-- 7. 位置情報ルーティング
{
"Comment": "CREATE/DELETE/UPSERT a record ",
"Changes": [
{ "Action": "UPSERT",
"ResourceRecordSet": { "Name": "www.xxxxxxxxxxxx.link.",
"Type": "A",
"SetIdentifier": "rec1",
"GeoLocation": { "ContinentCode": "NA" },
"TTL": 10,
"ResourceRecords": [
{ "Value": "192.0.2.11" }
]
}
},
{ "Action": "UPSERT",
"ResourceRecordSet": { "Name": "www.xxxxxxxxxxxx.link.",
"Type": "A",
"SetIdentifier": "rec2",
"GeoLocation": { "ContinentCode": "EU" },
"TTL": 10,
"ResourceRecords": [
{ "Value": "192.0.2.12" }
]
}
}
]
}
aws route53 change-resource-record-sets \
--hosted-zone-id 333333333333333333333 \
--change-batch file://a.json
aws route53 list-resource-record-sets \
--hosted-zone-id 333333333333333333333
-- 8. レイテンシールーティング
{
"Comment": "CREATE/DELETE/UPSERT a record ",
"Changes": [
{ "Action": "UPSERT",
"ResourceRecordSet": { "Name": "www.xxxxxxxxxxxx.link.",
"Type": "A",
"SetIdentifier": "rec1",
"Region": "us-east-1",
"TTL": 10,
"ResourceRecords": [
{ "Value": "192.0.2.11" }
]
}
},
{ "Action": "UPSERT",
"ResourceRecordSet": { "Name": "www.xxxxxxxxxxxx.link.",
"Type": "A",
"SetIdentifier": "rec2",
"Region": "eu-west-3",
"TTL": 10,
"ResourceRecords": [
{ "Value": "192.0.2.12" }
]
}
}
]
}
aws route53 change-resource-record-sets \
--hosted-zone-id 333333333333333333333 \
--change-batch file://a.json
aws route53 list-resource-record-sets \
--hosted-zone-id 333333333333333333333
-- 9. フェイルオーバールーティング
{
"Comment": "CREATE/DELETE/UPSERT a record ",
"Changes": [
{ "Action": "UPSERT",
"ResourceRecordSet": { "Name": "www.xxxxxxxxxxxx.link.",
"Type": "A",
"SetIdentifier": "rec1",
"Failover": "PRIMARY",
"TTL": 10,
"ResourceRecords": [
{ "Value": "192.0.2.11" }
],
"HealthCheckId": "11111111-1111-1111-1111-111111111111"
}
},
{ "Action": "UPSERT",
"ResourceRecordSet": { "Name": "www.xxxxxxxxxxxx.link.",
"Type": "A",
"SetIdentifier": "rec2",
"Failover": "SECONDARY",
"TTL": 10,
"ResourceRecords": [
{ "Value": "192.0.2.12" }
],
"HealthCheckId": "22222222-2222-2222-2222-222222222222"
}
}
]
}
aws route53 change-resource-record-sets \
--hosted-zone-id 333333333333333333333 \
--change-batch file://a.json
aws route53 list-resource-record-sets \
--hosted-zone-id 333333333333333333333
-- 10. 複数値回答ルーティング
{
"Comment": "CREATE/DELETE/UPSERT a record ",
"Changes": [
{ "Action": "UPSERT",
"ResourceRecordSet": { "Name": "www.xxxxxxxxxxxx.link.",
"Type": "A",
"SetIdentifier": "rec1",
"MultiValueAnswer": true,
"TTL": 10,
"ResourceRecords": [
{ "Value": "192.0.2.11" }
],
"HealthCheckId": "11111111-1111-1111-1111-111111111111"
}
},
{ "Action": "UPSERT",
"ResourceRecordSet": { "Name": "www.xxxxxxxxxxxx.link.",
"Type": "A",
"SetIdentifier": "rec2",
"MultiValueAnswer": true,
"TTL": 10,
"ResourceRecords": [
{ "Value": "192.0.2.12" }
],
"HealthCheckId": "22222222-2222-2222-2222-222222222222"
}
}
]
}
aws route53 change-resource-record-sets \
--hosted-zone-id 333333333333333333333 \
--change-batch file://a.json
aws route53 list-resource-record-sets \
--hosted-zone-id 333333333333333333333
-- 11. クリーンアップ
-- レコードの削除
-- ヘルスチェックの削除
aws route53 list-health-checks
aws route53 delete-health-check \
--health-check-id 11111111-1111-1111-1111-111111111111
aws route53 delete-health-check \
--health-check-id 22222222-2222-2222-2222-222222222222
-- EC2インスタンスの削除
-- デフォルトのセキュリティグループでインバウンドHTTP (0.0.0.0/0)を取り消し