Cloudformation:VPC 路由 table,没有互联网网关路由

Cloudformation: VPC Routing table with No Route for Internet Gateway

我正在使用 CloudFormation 创建整个堆栈。我注意到,即使我确实有 0.0.0.0/0 的路由规则来访问我的云形成模板中的互联网网关,它也没有被创建。

专有网络:

"vpc": {
  "Type": "AWS::EC2::VPC",
  "Properties": {
    "CidrBlock": "172.31.0.0/16",
    "InstanceTenancy": "default",
    "EnableDnsSupport": "true",
    "EnableDnsHostnames": "true",
    "Tags": [
      {
        "Key": "Environment",
        "Value": {
          "Ref": "Env"
        }
      }
    ]
  }

路由table:

"rtb": {
  "Type": "AWS::EC2::RouteTable",
  "Properties": {
    "VpcId": {
      "Ref": "vpc"
    }
  },
  "Metadata": {
    "AWS::CloudFormation::Designer": {
      "id": "65297cdc-8bcd-482d-af40-b0fef849b8c2"
    }
  }
}

VPC网关附件:

"gw1": {
  "Type": "AWS::EC2::VPCGatewayAttachment",
  "Properties": {
    "VpcId": {
      "Ref": "vpc"
    },
    "InternetGatewayId": {
      "Ref": "ig"
    }
  },
  "Metadata": {
    "AWS::CloudFormation::Designer": {
      "id": "aa69d6c0-3b11-43be-a8c1-7e79176f8c89"
    }
  }
}

路线:

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

互联网网关:

"ig": {
  "Type": "AWS::EC2::InternetGateway",
  "Properties": {},
  "Metadata": {
    "AWS::CloudFormation::Designer": {
      "id": "9f9b4ce3-b994-43ff-9155-04aeb7ab2edf"
    }
  }
}

正在创建所有项目,VPC 的 IG 路由规则除外。 cloudformation堆栈创建没有错误。

路由table:

Destination: 172.31.0.0/16
Target: local

预期路由 table:

Destination: 172.31.0.0/16
Target: local
Destination: 0.0.0.0/0
Target: igw-********

注意我可以在cloudformation栈创建后直接自己添加规则

有什么我遗漏的吗?

联系 AWS 支持后,发现每个 VPC 都会自动创建一个路由 table,并且默认为其所有子网设置。解决方案是使用 SubnetRouteTableAssociation 将我的新路由 table 与每个子网相关联。

    "subnet0RTA": {
      "Type" : "AWS::EC2::SubnetRouteTableAssociation",
      "Properties" : {
        "RouteTableId" : {"Ref" : "rtb"},
        "SubnetId" : {"Ref" : "subnet0"}
      }
    },
    "subnet1RTA": {
      "Type" : "AWS::EC2::SubnetRouteTableAssociation",
      "Properties" : {
        "RouteTableId" : {"Ref" : "rtb"},
        "SubnetId" : {"Ref" : "subnet1"}
      }
    },