是否可以更改与 VPC 关联的路由表?我正在使用 CloudFormation 并创建了自己的 RT 和与之关联的子网。但是,由于 VPC 使用的是默认路由表,并且它声称我没有显式关联子网,因此它们与主路由表关联作为包罗万象。我显然做错了,因为我的子网与我想要的路由表相关联,但默认路由表似乎优先。
这表明子网是关联的:
这表示子网不与路由表关联:
如果我将 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