是否可以更改与VPC关联的路由表?我正在使用CloudFormation,并使用它创建了自己的RT和相关子网。但是,由于VPC使用的是默认路由表,而且它声称我没有显式关联子网,所以它们与主路由表关联为catch all。我显然做错了什么,因为我的子网与我想要的路由表相关联,但是默认的路由表似乎是优先的。
这表明子网是相关联的:

这表明子网与路由表没有关联:

如果我将IGW路由添加到默认/主RT中,则一切都正常。但不是我想要的。
更新
下面是创建VPC和组件的CloudFormation。问题是,如果在子网中旋转了一个盒子,那么尽管我的子网显式地与我的自定义路由表相关联,主路由表还是被使用了。
Resources:
TransitVPC:
Type: 'AWS::EC2::VPC'
Properties:
CidrBlock: !Ref TransitVpcCidr
EnableDnsSupport: 'true'
EnableDnsHostnames: 'true'
Tags:
- Key: Name
Value: Transit VPC
TransitInternetGateway:
Type: 'AWS::EC2::InternetGateway'
Properties:
Tags:
- Key: Name
Value: Transit Internet Gateway
DependsOn:
- TransitVPC
TransitRouteTable:
Type: 'AWS::EC2::RouteTable'
Properties:
VpcId: !Ref TransitVPC
Tags:
- Key: Name
Value: Transit VPC RT
DependsOn:
- TransitVPC
TransitIGWAttachment:
Type: 'AWS::EC2::VPCGatewayAttachment'
Properties:
InternetGatewayId: !Ref TransitInternetGateway
VpcId: !Ref TransitVPC
DependsOn:
- TransitVPC
- TransitInternetGateway
TransitSubnetA:
Type: 'AWS::EC2::Subnet'
Properties:
VpcId: !Ref TransitVPC
CidrBlock: !Ref TransitSubnetACidr
AvailabilityZone: !Ref TransitSubnetARegion
Tags:
- Key: Name
Value: Transit VPC Subnet A
DependsOn:
- TransitVPC
TransitSubnetARTAssoc:
Type: 'AWS::EC2::SubnetRouteTableAssociation'
Properties:
RouteTableId: !Ref TransitRouteTable
SubnetId: !Ref TransitSubnetA
TransitSubnetB:
Type: 'AWS::EC2::Subnet'
Properties:
VpcId: !Ref TransitVPC
CidrBlock: !Ref TransitSubnetBCidr
AvailabilityZone: !Ref TransitSubnetBRegion
Tags:
- Key: Name
Value: Transit VPC Subnet B
TransitSubnetBRTAssoc:
Type: 'AWS::EC2::SubnetRouteTableAssociation'
Properties:
SubnetId: !Ref TransitSubnetB
RouteTableId: !Ref TransitRouteTable
TransitIGWRoute:
Type: 'AWS::EC2::Route'
Properties:
RouteTableId: !Ref TransitRouteTable
DestinationCidrBlock: !Ref FinalGatewayCidr
GatewayId: !Ref TransitInternetGateway
DependsOn:
- TransitIGWAttachment
发布于 2019-02-27 21:36:00
最好是通过CloudFormation创建整个VPC,包括:
这样,它保证在以后再次部署时以同样的方式工作。此外,很容易引用堆栈中VPC的所有组件(而不是必须引用堆栈之外创建的资源)。
或者,您的模板可以创建自己的路由表(应该使用它而不是现有的路由表),然后创建一个子网关联,该将您的新子网配置为使用新的路由表。这样,默认的路由表将不会被使用,因为子网只会使用默认的路由表,如果它没有被专门分配给路由表。
https://stackoverflow.com/questions/54914548
复制相似问题