我们有一个互联网网关的VPC。 我们有3个子网(每个AZ有一个),并且想要为这三个子网使用一个路由表。 这个RT包含一条规则,将0.0.0.0/0路由到igw,但是当我们尝试将这个RT关联到多个子网时,在创build路由规则时堆栈创build失败,并提供以下错误消息:
route table rtb-xxxxxxx and network gateway igw-xxxxx belong to different networks.
这很奇怪,因为igw没有连接到子网,而是连接到VPC本身。
为了使模板工作,我需要做的只是与RT有1个子网关联,然后用另外两个更新堆栈。
我已经尝试添加2个等待条件,一个绑定到RT的创build,另一个创build路由规则,但他们不解决问题 – 我仍然得到同样的该死的规则:(
任何人都可以阐明我需要做什么来解决这个问题?
您确定您已将InternetGatway连接到VPC(或与路由表相同的VPC)。 在云的形成,这看起来像…
"AttachInternetGateway" : { "Type" : "AWS::EC2::VPCGatewayAttachment", "Properties" : { "VpcId" : { "Ref" : "YourVpc" }, "InternetGatewayId" : { "Ref" : "InternetGateway" } } },
正如@马库斯在回答他自己的问题时解释的那样; 当您在指定网关的位置创buildAWS :: EC2 :: Route条目时,缺lessDependsOn属性。
对于指定网关的路由条目,必须指定网关连接资源的依赖关系。
在接收到同样的错误,并且我的脑海中,当IGW连接到VPC时,这是如何失败的,这是AWS::EC2::Route声明中的一个简单变化。
"VPC" : { "Type" : "AWS::EC2::VPC", "Properties" : {"CidrBlock" : "10.1.0.0/16"} }, "InternetGateway" : { "Type" : "AWS::EC2::InternetGateway" }, "InternetGatewayAttachment" : { "Type" : "AWS::EC2::VPCGatewayAttachment", "Properties" : { "VpcId" : {"Ref" : "VPC"}, "InternetGatewayId" : {"Ref" : "InternetGateway"} } }, "ManagementRouteTable" : { "Type" : "AWS::EC2::RouteTable", "Properties" : { "VpcId" : {"Ref" : "VPC"} } }, "NATDefaultRoute" : { "Type" : "AWS::EC2::Route", "Properties" : { "RouteTableId" : {"Ref" : "ManagementRouteTable"}, "DestinationCidrBlock" : "0.0.0.0/0", "GatewayId" : {"Ref" : "InternetGateway"} } }
"VPC" : { "Type" : "AWS::EC2::VPC", "Properties" : {"CidrBlock" : "10.1.0.0/16"} }, "InternetGateway" : { "Type" : "AWS::EC2::InternetGateway" }, "InternetGatewayAttachment" : { "Type" : "AWS::EC2::VPCGatewayAttachment", "Properties" : { "VpcId" : {"Ref" : "VPC"}, "InternetGatewayId" : {"Ref" : "InternetGateway"} } }, "ManagementRouteTable" : { "Type" : "AWS::EC2::RouteTable", "Properties" : { "VpcId" : {"Ref" : "VPC"} } }, "NATDefaultRoute" : { "DependsOn" : "InternetGatewayAttachment", "Type" : "AWS::EC2::Route", "Properties" : { "RouteTableId" : {"Ref" : "ManagementRouteTable"}, "DestinationCidrBlock" : "0.0.0.0/0", "GatewayId" : {"Ref" : "InternetGateway"} } }
我find了一个修复。 我在等待条件正确的轨道上,但事实certificate,我需要添加一个DependsOn属性的规则,以便它依赖于首先创build的igw。
这就是我们如何将多个子网与相同的路由表相关联:
... "PublicSubnetA": { "Type": "AWS::EC2::Subnet", "Properties": { "AvailabilityZone": "..", "CidrBlock": "...", "VpcId": { "Ref": "VPC" }, "Tags": [ .. ] }}, "PublicSubnetB": { "Type": "AWS::EC2::Subnet", "Properties": { "AvailabilityZone": "..", "CidrBlock": "...", "VpcId": { "Ref": "VPC" }, "Tags": [ .. ] }}, "RouteTableIGW": { "Type": "AWS::EC2::RouteTable", "Properties": { "VpcId": { "Ref": "VPC" }, "Tags": [ .. ]}}, "...": { "Type": "AWS::EC2::SubnetRouteTableAssociation", "Properties": { "RouteTableId": { "Ref": "RouteTableIGW" }, "SubnetId": { "Ref": "PublicSubnetA" }} }, "...": { "Type": "AWS::EC2::SubnetRouteTableAssociation", "Properties": { "RouteTableId": { "Ref": "RouteTableIGW" }, "SubnetId": { "Ref": "PublicSubnetB" }} }, ...
它工作得很好。 我通过这种方式将一个IGW指导的路由表与2个公有子网和另一个NAT指导的路由表与4个私有子网联系起来。
您应该使用attachwayway将多个子网连接到路由表和Internet网关。 因此它与vpc连接internetgateway