【问题标题】:Cloudformation: VPC Routing table with No Route for Internet GatewayCloudformation:互联网网关没有路由的 VPC 路由表
【发布时间】:2017-07-15 05:40:59
【问题描述】:

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

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

路由表:

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

VPCGateway附件:

"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 堆栈创建没有错误。

路由表:

Destination: 172.31.0.0/16
Target: local

预期的路由表:

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

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

我有什么遗漏吗?

【问题讨论】:

  • 资源在我看来是正确的 - 请添加堆栈事件历史记录的完整输出(控制台中的Events 选项卡),以防出现异常情况。
  • 我认为共享堆栈的整个输出有点不安全。我刚刚仔细检查过,没有错误或警告,都具有 CREATE_COMPLETE 的状态。首先创建ig,然后创建vpc,然后创建rtbgw1,最后创建route1。我认为这是一个错误。

标签: amazon-web-services amazon-cloudformation


【解决方案1】:

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

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

【讨论】:

  • 非常感谢@zed,这真的很有帮助。
  • 嗨@zed,我有类似的问题,找不到解决方案,如果您只是在模板中添加了以下几行或做了其他任何事情,请告诉我?谢谢:)
  • @virusivv 这是整个解决方案,您可能需要将参考更改为您的资源参考。
  • 必须更改已知的引用
猜你喜欢
  • 2020-04-04
  • 2020-03-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-01-26
  • 2019-05-06
相关资源
最近更新 更多