VPCピアリング、別リージョン間の設定で久しぶりに躓いた。
環境はこう。
- Requester: ap-northeast-3 (大阪) / profile-requester
- Accepter: ap-northeast-1 (東京) / profile-accepter
別アカウント × 別リージョン。面倒なパターン。
やらかしたこと
create-vpc-peering-connection 実行。一見成功したように見えてpcx-xxxxxが発行された。Accepter側で承認しようとしたらNotFoundエラー。
An error occurred (InvalidVpcPeeringConnectionID.NotFound) when calling the AcceptVpcPeeringConnection operation調べたらそのIDはfailed状態になってた。削除しようとしてもInvalidStateTransition。
An error occurred (InvalidStateTransition) when calling the DeleteVpcPeeringConnection operationfailedからdeletingへの遷移不可。手が出せない。
原因
—peer-region の指定を忘れてた。クロスリージョンの場合は必須。これがないとAWSは同一リージョン内のピアリングとして処理し、対象VPCが見つからず即座にfailedになる。
failed状態のリソースは手動削除不可。しばらくしたらAWSが勝手に消してくれる。
正しいコマンド
Requester側 (大阪) で作成:
aws ec2 create-vpc-peering-connection \ --region ap-northeast-3 \ --profile profile-requester \ --vpc-id vpc-requester-id \ --peer-vpc-id vpc-accepter-id \ --peer-owner-id 123456789012 \ --peer-region ap-northeast-1Accepter側 (東京) で承認:
aws ec2 accept-vpc-peering-connection \ --region ap-northeast-1 \ --profile profile-accepter \ --vpc-peering-connection-id pcx-new-id承認時もAccepter側のリージョンを指定するのを忘れずに。
接続後の作業
activeになっても通信はまだできない。
- 両VPCのルートテーブル: 相手側CIDRをpcxに向ける
- 両VPCのセキュリティグループ: 相手側CIDRからのインバウンド許可
クロスリージョンではセキュリティグループIDでの参照不可。CIDR指定必須。
教訓
—peer-region は忘れがち。failedになったら焦らず放置でOK。
hsb.horse