- Newest
- Most votes
- Most comments
Hello,
In the context of Amazon Web Services (AWS) and CloudFormation (CFN), the term "main" route table refers to the default route table that is automatically associated with your VPC when it is created. This main route table is used to route traffic within the VPC unless a custom route table is explicitly associated with a subnet. To set your custom route table as the main route table for your VPC, you'll need to disassociate the existing main route table from all of your subnets and then associate your custom route table with those subnets instead. Here's you can do it: Use the AWS Management Console, AWS CLI, or CloudFormation to disassociate the main route table from all subnets in your VPC. You can do this by removing the subnet associations from the main route table. Once the main route table is disassociated from all subnets, associate your custom route table with the desired subnets using the same method you used to associate the initial route table.
https://docs.aws.amazon.com/vpc/latest/userguide/WorkWithRouteTables.html#Route_Replacing_Main_Table
please look at this below policy:
Resources:
MyRouteTable:
Type: AWS::EC2::RouteTable
Properties:
VpcId: YourVpcId
MyRoute:
Type: AWS::EC2::Route
Properties:
RouteTableId: !Ref MyRouteTable
DestinationCidrBlock: 0.0.0.0/0
GatewayId: YourInternetGatewayId
MySubnetAssociation:
Type: AWS::EC2::SubnetRouteTableAssociation
Properties:
SubnetId: YourSubnetId
RouteTableId: !Ref MyRouteTable
Main route table—The route table that automatically comes with your VPC. It controls the routing for all subnets that are not explicitly associated with any other route table.
https://docs.aws.amazon.com/vpc/latest/userguide/VPC_Route_Tables.html
So if you have created a new Route Table and associated it with your subnets, you don't need to make the route table "main".
Relevant content
- asked 3 years ago
- asked 2 years ago
- AWS OFFICIALUpdated 2 years ago
- AWS OFFICIALUpdated 5 months ago
- AWS OFFICIALUpdated 3 years ago
- AWS OFFICIALUpdated 6 months ago
How to use CloudFormation to disassociate the main route table from all subnets?
To disassociate the main route table from all subnets using AWS CloudFormation, you can use the AWS::EC2::Subnet resource to explicitly specify the route table association. By not specifying any route table association for a subnet, it will automatically revert to the VPC's default main route table please look at the policy below: Resources: MySubnet: Type: AWS::EC2::Subnet Properties: VpcId: YourVpcId CidrBlock: YourSubnetCIDR
MySubnetAssociation: Type: AWS::EC2::SubnetRouteTableAssociation Properties: SubnetId: !Ref MySubnet RouteTableId: '' MySubnet is the subnet resource you want to disassociate from the main route table. MySubnetAssociation is the association between the subnet and the route table. By setting RouteTableId to an empty string (''), you're effectively disassociating the subnet from any route table.
After deploying this CloudFormation stack, the specified subnet will revert to using the VPC's default main route table. Repeat this process for each subnet in your VPC to completely disassociate the main route table from all subnets
please Rember the change before use the policy YourVpcId and YourSubnetCIDR.