【问题标题】:Cloudformation error: route table X and network gateway Y belong to different networksCloudformation 错误:路由表 X 和网络网关 Y 属于不同的网络
【发布时间】:2018-07-29 15:56:34
【问题描述】:

我有以下网络 ELB 网络资源配置,以便通过单个弹性 ip 路由出站流量。

我收到以下错误:

"AWS::EC2::Route PublicRoute CREATE_FAILED: 路由表 rtb-zzzeb 和网络网关 igw-xxx 属于不同的网络"

在我的以下配置的上下文中,这到底意味着什么?我标记为“PublicRoute”的资源有问题吗?

Resources:
  VPC:
      Type: AWS::EC2::VPC
      Properties:
        CidrBlock: "10.0.0.0/24"
  Public1aSBN:
    Type: AWS::EC2::Subnet
    Properties:
      VpcId: !Ref VPC
      CidrBlock: "10.0.0.128/27"
      AvailabilityZone: "eu-west-2a"
  Public1cSBN:
    Type: AWS::EC2::Subnet
    Properties:
      VpcId: !Ref VPC
      CidrBlock: "10.0.0.160/27"
      AvailabilityZone: "eu-west-2c"
  Public1bSBN:
      Type: AWS::EC2::Subnet
      Properties:
        VpcId: !Ref VPC
        CidrBlock: "10.0.0.192/27"
        AvailabilityZone: "eu-west-2b"
  InternetGateway:
    Type: "AWS::EC2::InternetGateway"
  AttachGateway:
    Type: AWS::EC2::VPCGatewayAttachment
    Properties:
      VpcId: !Ref VPC
      InternetGatewayId: !Ref InternetGateway
  EIPNatGateway:
    Type: AWS::EC2::EIP
    Properties:
      Domain: vpc
  NAT:
    DependsOn: EIPNatGateway
    Type: AWS::EC2::NatGateway
    Properties:
      AllocationId:
        Fn::GetAtt:
        - EIPNatGateway
        - AllocationId
      SubnetId: !Ref Public1aSBN
  RouteTablePublic:
    Type: AWS::EC2::RouteTable
    Properties:
      VpcId: !Ref VPC
  Public1aSubnetRouteTableAssociation:
    Type: AWS::EC2::SubnetRouteTableAssociation
    Properties:
      SubnetId: !Ref Public1aSBN
      RouteTableId: !Ref RouteTablePublic
  Public1cSubnetRouteTableAssociation:
    Type: AWS::EC2::SubnetRouteTableAssociation
    Properties:
      SubnetId: !Ref Public1cSBN
      RouteTableId: !Ref RouteTablePublic
  Public1bSubnetRouteTableAssociation:
    Type: AWS::EC2::SubnetRouteTableAssociation
    Properties:
      SubnetId: !Ref Public1bSBN
      RouteTableId: !Ref RouteTablePublic
  PublicRoute:
    Type: AWS::EC2::Route
    DependsOn: InternetGateway
    Properties:
      RouteTableId: !Ref RouteTablePublic
      DestinationCidrBlock: 0.0.0.0/0
      GatewayId: !Ref InternetGateway
  TargetSG:
    Type: AWS::EC2::SecurityGroup
    Properties:
      VpcId: !Ref VPC
  InboundRule:
    Type: AWS::EC2::SecurityGroupIngress
    DependsOn: TargetSG
    Properties:
      IpProtocol: -1
      FromPort: '0'
      ToPort: '65535'
      CidrIp: "0.0.0.0/0"
      GroupId:
        Fn::GetAtt:
          - TargetSG
          - GroupId

【问题讨论】:

  • 我能够使用相同的模板成功创建堆栈(尽管我必须修复安全组描述的错误)。我无法重现提到的错误,这是完整的模板吗?

标签: amazon-web-services amazon-cloudformation


【解决方案1】:

根据docs

VPC 中的某些资源需要网关(互联网或 VPN 网关)。如果您的 AWS CloudFormation 模板定义了 VPC、网关和网关附件,则任何需要网关的资源都依赖于网关附件。

这意味着您必须将您的AttachGateway 添加到您的PublicRoute 资源的DependsOn 属性中:

PublicRoute:
  Type: AWS::EC2::Route
  DependsOn: 
    - InternetGateway
    - AttachGateway
  Properties:
    RouteTableId: !Ref RouteTablePublic
    DestinationCidrBlock: 0.0.0.0/0
    GatewayId: !Ref InternetGateway

这可确保您的资源以正确的顺序构建,因此在网关连接到 vpc 之前不会创建您的路由

【讨论】:

    【解决方案2】:

    如果路由表和 Internet 网关在不同的 VPC 中,您将收到此错误。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-06-23
      • 1970-01-01
      • 2020-05-13
      • 1970-01-01
      • 1970-01-01
      • 2022-09-23
      • 1970-01-01
      • 2017-07-15
      相关资源
      最近更新 更多