使用这个AWS walkthrough ,我可以在不同的 aws 账户之间成功添加 vpc 对等连接。
连接会自动接受,因为接受者账户中的 IAM 角色设置已被授予该权限,并在请求连接时在请求者账户中被引用。
这一切都很好,但是两个 VPC 中没有路由表条目,此连接就没有意义。
查看示例中的第二个模板;创建 AWS::EC2::VPCPeeringConnection
的那个,有没有办法在第一个模板中创建的 VPC 的路由表条目中添加路由?
我当然可以将路由表id传递给第二个模板,但我认为这还不够。我认为帐户之间必须存在额外的信任关系才能实现这一点。
知道如何做到这一点吗?
最佳答案
可以从第二个模板中在第一个 VPC 中创建路由表条目。您可以在第二个模板中包含的相关 CloudFormation 资源示例:
Resources:
IsolationVPC:
Type: AWS::EC2::VPC
Properties:
CidrBlock: "10.1.0.0/16"
PrimaryPrivateSubnet:
DependsOn:
- IsolationVPC
Type: AWS::EC2::Subnet
Properties:
VpcId:
Ref: IsolationVPC
AvailabilityZone: ${self:provider.region}a
CidrBlock: 10.1.1.0/24
PrimaryPrivateSubnetRouteTable:
Type: AWS::EC2::RouteTable
Properties:
VpcId:
Ref: IsolationVPC
DependsOn:
- IsolationVPC
PrimaryPublicSubnet:
DependsOn:
- IsolationVPC
Type: AWS::EC2::Subnet
Properties:
VpcId:
Ref: IsolationVPC
AvailabilityZone: ${self:provider.region}a
CidrBlock: 10.1.2.0/24
PrimaryPublicSubnetRouteTable:
Type: AWS::EC2::RouteTable
Properties:
VpcId:
Ref: IsolationVPC
DependsOn:
- IsolationVPC
PeeringConnection:
Type: AWS::EC2::VPCPeeringConnection
DependsOn:
- IsolationVPC
Properties:
PeerVpcId: <first VPC ID goes here>
VpcId:
Ref: IsolationVPC
PublicRoutingTableEntry:
Type: AWS::EC2::Route
DependsOn:
- PrimaryPublicSubnetRouteTable
- PeeringConnection
Properties:
RouteTableId:
Ref: PrimaryPublicSubnetRouteTable
DestinationCidrBlock: <first VPC CIDR block goes here>
VpcPeeringConnectionId:
Ref: PeeringConnection
PrivateRoutingTableEntry:
Type: AWS::EC2::Route
DependsOn:
- PrimaryPrivateSubnetRouteTable
- PeeringConnection
Properties:
RouteTableId:
Ref: PrimaryPrivateSubnetRouteTable
DestinationCidrBlock: <first VPC CIDR block goes here>
VpcPeeringConnectionId:
Ref: PeeringConnection
ReversePublicRoutingTableEntry:
Type: AWS::EC2::Route
DependsOn:
- PeeringConnection
Properties:
RouteTableId: <first VPC public route table ID goes here>
DestinationCidrBlock: 10.1.0.0/16
VpcPeeringConnectionId:
Ref: PeeringConnection
ReversePrivateRoutingTableEntry:
Type: AWS::EC2::Route
DependsOn:
- PeeringConnection
Properties:
RouteTableId: <first VPC private route table ID goes here>
DestinationCidrBlock: 10.1.0.0/16
VpcPeeringConnectionId:
Ref: PeeringConnection
直到我阅读此处提供的示例时我才意识到这一点:https://github.com/lizduke/cloudformationexamples但后来测试成功。
关于amazon-web-services - 在 CloudFormation 中跨不同 AWS 账户添加 VPC 对等路由,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48932117/