Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in AWS by (5.6k points)

I have created a stack using CloudFormation. Even I have a routing rule for 0.0.0.0/0 to access an internet gateway in cloud formation, it is not being created.

VPC:

"vpc": {

  "Type": "AWS::EC2::VPC",

  "Properties": {

    "CidrBlock": "172.31.0.0/16",

    "InstanceTenancy": "default",

    "EnableDnsSupport": "true",

    "EnableDnsHostnames": "true",

    "Tags": [

      {

        "Key": "Environment",

        "Value": {

          "Ref": "Env"

        }

      }

    ]

  }

Routing Table:

"rtb": {

  "Type": "AWS::EC2::RouteTable",

  "Properties": {

    "VpcId": {

      "Ref": "vpc"

    }

  },

  "Metadata": {

    "AWS::CloudFormation::Designer": {

      "id": "65297cdc-8bcd-482d-af40-b0fef849b8c2"

    }

  }

}

VPCGatewayAttachment:

"gw1": {

  "Type": "AWS::EC2::VPCGatewayAttachment",

  "Properties": {

    "VpcId": {

      "Ref": "vpc"

    },

    "InternetGatewayId": {

      "Ref": "ig"

    }

  },

  "Metadata": {

    "AWS::CloudFormation::Designer": {

      "id": "aa69d6c0-3b11-43be-a8c1-7e79176f8c89"

    }

  }

}

Route:

"route1": {

  "Type": "AWS::EC2::Route",

  "Properties": {

    "DestinationCidrBlock": "0.0.0.0/0",

    "RouteTableId": {

      "Ref": "rtb"

    },

    "GatewayId": {

      "Ref": "ig"

    }

  },

  "DependsOn": "gw1",

  "Metadata": {

    "AWS::CloudFormation::Designer": {

      "id": "a68dd12e-3c14-4fa9-ba36-e0046374a0e9"

    }

  }

}

Internet Gateway:

"ig": {

  "Type": "AWS::EC2::InternetGateway",

  "Properties": {},

  "Metadata": {

    "AWS::CloudFormation::Designer": {

      "id": "9f9b4ce3-b994-43ff-9155-04aeb7ab2edf"

    }

  }

}

There are no errors in the stack creation but the IG routing rule is not created.

Where I'm missing?

1 Answer

0 votes
by (12.4k points)

So VPC creates a routing table automatically and it is set by default for all of its subnets. So the solution would be to use a "SubnetRouteTableAssociation" to associate my new route table with each subnet:

"subnet0RTA": {

      "Type" : "AWS::EC2::SubnetRouteTableAssociation",

      "Properties" : {

        "RouteTableId" : {"Ref" : "rtb"},

        "SubnetId" : {"Ref" : "subnet0"}

      }

    },

    "subnet1RTA": {

      "Type" : "AWS::EC2::SubnetRouteTableAssociation",

      "Properties" : {

        "RouteTableId" : {"Ref" : "rtb"},

        "SubnetId" : {"Ref" : "subnet1"}

      }

    },

Interested in learning more about AWS? Do check out some amazing AWS Developer Training Online offered by Intellipaat!

Related questions

Want to get 50% Hike on your Salary?

Learn how we helped 50,000+ professionals like you !

0 votes
1 answer
0 votes
1 answer
asked Sep 14, 2020 in AWS by Justin (7k points)
0 votes
1 answer
asked Mar 14, 2021 in AWS by devin (5.6k points)
0 votes
1 answer

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...