How to set a route table as 'main' and what does it mean?

0

In my CFN template, I'm creating a route table, associating to my subnet and then creating a route to allow traffic to go to internet via internet gateway

It has been created, but now I've 2 route table, one was the default route, created from AWS. i cannot delete it because it's the main route table

so how can I set my route table as main?

What does it mean 'main' in this context?

asked a month ago110 views
2 Answers
3
Accepted Answer

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

answered a month ago
profile picture
EXPERT
reviewed a month 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.

1

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".

profile picture
EXPERT
answered a month ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions