アカウントAで、アカウントBのプライベートホストゾーンの名前解決をしたい場合は反対の作業をやる
| アカウントA | アカウントB | |
|---|---|---|
| (1) | プライベートホストゾーンの作成 | |
| (2) | 利用可能なプライベートホストゾーンを一覧表示 aws route53 list-hosted-zones | |
| (3) | アカウントAのプライベートホストゾーンをアカウントBのVPCからの関連付け許可依頼 aws route53 create-vpc-association-authorization | |
| (4) | アカウントAのプライベートホストゾーンをアカウントBのVPCへ関連付け aws route53 associate-vpc-with-hosted-zone |
|
| (5) | Route53に関連付けされているVPCを確認 | |
| 関連付けの許可を削除 | ||
| (6) | VPC関連付けを許可しているVPCを表示 aws route53 list-vpc-association-authorizations | |
| (7) | VPC関連付けの許可を削除 aws route53 delete-vpc-association-authorization | |
| (8) | VPC関連付けを許可しているVPCを表示 aws route53 list-vpc-association-authorizations | |
aws route53 list-hosted-zones )
$ aws route53 list-hosted-zones
{
"HostedZones": [
{
(略)
{
"Id": "/hostedzone/Z01363732OJ20G9YLROAW",
"Name": "example.com.",
"CallerReference": "2021-09-01_01-52-27",
"Config": {
"PrivateZone": false
},
"ResourceRecordSetCount": 2
}
(略)
アカウント A のプライベートホストゾーンとアカウント B の VPC との関連付けを許可します。
$ HOSTED_ZONE_ID=<hosted-zone-id> # アカウントAのプライベート ホストゾーンID
$ VPC_ID=<vpc-id> # アカウントBの VPC ID
$ REGION=ap-northeast-1 # アカウントBのリージョン
# [create-vpc-association-authorization] を実行
$ aws route53 create-vpc-association-authorization \
--hosted-zone-id ${HOSTED_ZONE_ID} \
--vpc VPCRegion=${REGION},VPCId=${VPC_ID} \
--region ${REGION}
アカウント A のプライベートホストゾーンとアカウント B の VPC 間の関連付けを作成します。
$ HOSTED_ZONE_ID=<hosted-zone-id> # アカウントAのプライベート ホストゾーンID
$ VPC_ID=<vpc-id> # アカウントBの VPC ID
$ REGION=ap-northeast-1
# [associate-vpc-with-hosted-zone] を実行
$ aws route53 associate-vpc-with-hosted-zone \
--hosted-zone-id ${HOSTED_ZONE_ID} \
--vpc VPCRegion=${REGION},VPCId=${VPC_ID} \
--region ${REGION}
アカウントAのRoute53 画面を更新すると、[関連付けられたVPC] にアカウントBの VPC ID が追加されています。
アソシエーションを作成したら、アソシエーション権限を削除するのがベストプラクティスです。
同じVPC IDからのVPC関連付けの再実行を防ぐためです。
$ HOSTED_ZONE_ID=<hosted-zone-id> # アカウントAのプライベート ホストゾーンID
$ VPC_ID=<vpc-id> # アカウントBの VPC ID
$ REGION=ap-northeast-1
$ aws route53 list-vpc-association-authorizations \
--hosted-zone-id ${HOSTED_ZONE_ID}
$ HOSTED_ZONE_ID=<hosted-zone-id> # アカウントAのプライベート ホストゾーンID
$ VPC_ID=<vpc-id> # アカウントBの VPC ID
$ REGION=ap-northeast-1
$ aws route53 delete-vpc-association-authorization \
--hosted-zone-id ${HOSTED_ZONE_ID} \
--vpc VPCRegion=${REGION},VPCId=${VPC_ID} \
--region ${REGION}
$ HOSTED_ZONE_ID=<hosted-zone-id> # アカウントAのプライベート ホストゾーンID
$ VPC_ID=<vpc-id> # アカウントBの VPC ID
$ REGION=ap-northeast-1
$ aws route53 list-vpc-association-authorizations \
--hosted-zone-id ${HOSTED_ZONE_ID}