【问题标题】:Getting a InvalidRouteTableID.NotFound in cloud formation for resources that exist在云形成中为现有资源获取 InvalidRouteTableID.NotFound
【发布时间】:2021-04-21 15:08:25
【问题描述】:

我在运行时在云形成堆栈中反复获得InvalidRouteTableID.NotFound

aws cloudformation create-stack --stack-name sample --template-body file://aws-network.yml

我不知道为什么。

这是我的 cloudformation 模板aws-network.yml。它非常标准,它创建 VPC、子网、互联网网关、弹性 IP 地址、nat 网关、路由表和关联。

AWSTemplateFormatVersion: 2010-09-09
# This CloudFormation template deploys a basic VPC / Network. 
Resources:
  vpc:
    Type: AWS::EC2::VPC
    Properties:
      CidrBlock: 10.0.0.0/16
      EnableDnsHostnames: true
      EnableDnsSupport: false 
      InstanceTenancy: default
      Tags:
        - Key: Name
          Value: !Join ['', [!Ref "AWS::StackName", "-vpc"]]
  internetGateway:
    Type: AWS::EC2::InternetGateway
    DependsOn: vpc
    Properties:
      Tags:
        - Key: Name
          Value: !Join ['', [!Ref "AWS::StackName", "-igw"]]
  attachGateway:
    Type: AWS::EC2::VPCGatewayAttachment
    Properties:
      VpcId: !Ref vpc
      InternetGatewayId: !Ref internetGateway
  publicSubnetA:
    Type: AWS::EC2::Subnet
    Properties:
      VpcId: !Ref vpc
      CidrBlock: 10.0.10.0/24
      AvailabilityZone: !Select [ 0, !GetAZs ]
      Tags:
        - Key: Name
          Value: !Join ['', [!Ref "AWS::StackName", "-public-a"]]
  publicSubnetB:
    Type: AWS::EC2::Subnet
    Properties:
      VpcId: !Ref vpc
      CidrBlock: 10.0.20.0/24
      AvailabilityZone: !Select [ 1, !GetAZs ]
      Tags:
        - Key: Name
          Value: !Join ['', [!Ref "AWS::StackName", "-public-b"]]
  privateSubnetA:
    Type: AWS::EC2::Subnet
    Properties:
      VpcId: !Ref vpc
      CidrBlock: 10.0.30.0/24
      AvailabilityZone: !Select [ 0, !GetAZs ]
      Tags:
        - Key: Name
          Value: !Join ['', [!Ref "AWS::StackName", "-private-a"]]
  privateSubnetB:
    Type: AWS::EC2::Subnet
    Properties:
      VpcId: !Ref vpc
      CidrBlock: 10.0.40.0/24
      AvailabilityZone: !Select [ 1, !GetAZs ]
      Tags:
        - Key: Name
          Value: !Join ['', [!Ref "AWS::StackName", "-private-b"]]
  publicRouteTable:
    Type: AWS::EC2::RouteTable
    Properties:
      VpcId: !Ref vpc
      Tags:
        - Key: Name
          Value: !Join ['', [!Ref "AWS::StackName", "-public"]]
  publicRoute1:
    Type: AWS::EC2::Route
    DependsOn: attachGateway
    Properties:
      RouteTableId: !Ref publicRouteTable
      DestinationCidrBlock: 0.0.0.0/0
      GatewayId: !Ref internetGateway
  natGateway: # it has a cost https://aws.amazon.com/vpc/pricing/
    Type: AWS::EC2::NatGateway
    Properties:
      AllocationId: !GetAtt elasticIpAddress.AllocationId # gets the allocation Id from the elasticIpAddress resource
      SubnetId: !Ref publicSubnetA # only associated to a public subnet to simplify and reduce costs
      Tags:
        - Key: Name
          Value: !Join ['', [!Ref "AWS::StackName", "-nat"]]
  elasticIpAddress:
    Type: AWS::EC2::EIP
    Properties:
      Domain: vpc
  privateRouteTable:
    Type: AWS::EC2::RouteTable
    Properties:
      VpcId: !Ref vpc
      Tags:
        - Key: Name
          Value: !Join ['', [!Ref "AWS::StackName", "-private"]]
  privateRoute1:
    Type: AWS::EC2::Route
    Properties:
      RouteTableId: !Ref privateRouteTable
      DestinationCidrBlock: 0.0.0.0/0
      NateGatewayId: !Ref natGateway
  publicSubnetARouteTableAssociation:
    Type: AWS::EC2::SubnetRouteTableAssociation
    Properties:
      SubnetId: !Ref publicSubnetA
      RouteTableId: publicRouteTable
  publicSubnetBRouteTableAssociation:
    Type: AWS::EC2::SubnetRouteTableAssociation
    Properties:
      SubnetId: !Ref publicSubnetB
      RouteTableId: publicRouteTable
  privateSubnetARouteTableAssociation:
    Type: AWS::EC2::SubnetRouteTableAssociation
    Properties:
      SubnetId: !Ref privateSubnetA
      RouteTableId: privateRouteTable
  privateSubnetBRouteTableAssociation:
    Type: AWS::EC2::SubnetRouteTableAssociation
    Properties:
      SubnetId: !Ref privateSubnetB
      RouteTableId: privateRouteTable

根据事件,这不应该发生,我可以按以下顺序看到:

2021-04-21 17:04:05 UTC+0200    privateRouteTable   
CREATE_COMPLETE -

2021-04-21 17:04:05 UTC+0200    publicRouteTable    
CREATE_COMPLETE -

2021-04-21 17:04:22 UTC+0200    privateSubnetBRouteTableAssociation 
CREATE_FAILED   The routeTable ID 'privateRouteTable' does not exist (Service: AmazonEC2; Status Code: 400; Error Code: InvalidRouteTableID.NotFound; Request ID: b51b2b9c-af12-4376-b6e4-1698624f7522; Proxy: null)

2021-04-21 17:04:22 UTC+0200    publicSubnetBRouteTableAssociation  
CREATE_FAILED   The routeTable ID 'publicRouteTable' does not exist (Service: AmazonEC2; Status Code: 400; Error Code: InvalidRouteTableID.NotFound; Request ID: 5cb26e14-13ca-4915-9973-109dd44c5b2e; Proxy: null)

2021-04-21 17:04:22 UTC+0200    attachGateway   
CREATE_FAILED   Resource creation cancelled

2021-04-21 17:04:23 UTC+0200    privateSubnetARouteTableAssociation 
CREATE_FAILED   Resource creation cancelled

2021-04-21 17:04:23 UTC+0200    publicSubnetARouteTableAssociation  
CREATE_FAILED   Resource creation cancelled

2021-04-21 17:04:23 UTC+0200    natGateway  
CREATE_FAILED   Resource creation cancelled

2021-04-21 17:04:24 UTC+0200    rubiko  
ROLLBACK_IN_PROGRESS    The following resource(s) failed to create: [publicSubnetBRouteTableAssociation, attachGateway, privateSubnetBRouteTableAssociation, natGateway, publicSubnetARouteTableAssociation, privateSubnetARouteTableAssociation]. Rollback requested by user.

知道为什么找不到某些已创建的资源吗?

谢谢

【问题讨论】:

    标签: amazon-web-services amazon-cloudformation


    【解决方案1】:

    解决了,我忘了!Ref(我会收工的..)

    这是正确的模板

    AWSTemplateFormatVersion: 2010-09-09
    # This CloudFormation template deploys a basic VPC / Network. 
    Resources:
      vpc:
        Type: AWS::EC2::VPC
        Properties:
          CidrBlock: 10.0.0.0/16
          EnableDnsHostnames: true
          EnableDnsSupport: false 
          InstanceTenancy: default
          Tags:
            - Key: Name
              Value: !Join ['', [!Ref "AWS::StackName", "-vpc"]]
      internetGateway:
        Type: AWS::EC2::InternetGateway
        DependsOn: vpc
        Properties:
          Tags:
            - Key: Name
              Value: !Join ['', [!Ref "AWS::StackName", "-igw"]]
      attachGateway:
        Type: AWS::EC2::VPCGatewayAttachment
        Properties:
          VpcId: !Ref vpc
          InternetGatewayId: !Ref internetGateway
      publicSubnetA:
        Type: AWS::EC2::Subnet
        Properties:
          VpcId: !Ref vpc
          CidrBlock: 10.0.10.0/24
          AvailabilityZone: !Select [ 0, !GetAZs ]
          Tags:
            - Key: Name
              Value: !Join ['', [!Ref "AWS::StackName", "-public-a"]]
      publicSubnetB:
        Type: AWS::EC2::Subnet
        Properties:
          VpcId: !Ref vpc
          CidrBlock: 10.0.20.0/24
          AvailabilityZone: !Select [ 1, !GetAZs ]
          Tags:
            - Key: Name
              Value: !Join ['', [!Ref "AWS::StackName", "-public-b"]]
      privateSubnetA:
        Type: AWS::EC2::Subnet
        Properties:
          VpcId: !Ref vpc
          CidrBlock: 10.0.30.0/24
          AvailabilityZone: !Select [ 0, !GetAZs ]
          Tags:
            - Key: Name
              Value: !Join ['', [!Ref "AWS::StackName", "-private-a"]]
      privateSubnetB:
        Type: AWS::EC2::Subnet
        Properties:
          VpcId: !Ref vpc
          CidrBlock: 10.0.40.0/24
          AvailabilityZone: !Select [ 1, !GetAZs ]
          Tags:
            - Key: Name
              Value: !Join ['', [!Ref "AWS::StackName", "-private-b"]]
      publicRouteTable:
        Type: AWS::EC2::RouteTable
        Properties:
          VpcId: !Ref vpc
          Tags:
            - Key: Name
              Value: !Join ['', [!Ref "AWS::StackName", "-public"]]
      publicRoute1:
        Type: AWS::EC2::Route
        DependsOn: attachGateway
        Properties:
          RouteTableId: !Ref publicRouteTable
          DestinationCidrBlock: 0.0.0.0/0
          GatewayId: !Ref internetGateway
      natGateway: # it has a cost https://aws.amazon.com/vpc/pricing/
        Type: AWS::EC2::NatGateway
        Properties:
          AllocationId: !GetAtt elasticIpAddress.AllocationId # gets the allocation Id from the elasticIpAddress resource
          SubnetId: !Ref publicSubnetA # only associated to a public subnet to simplify and reduce costs
          Tags:
            - Key: Name
              Value: !Join ['', [!Ref "AWS::StackName", "-nat"]]
      elasticIpAddress:
        Type: AWS::EC2::EIP
        Properties:
          Domain: vpc
      privateRouteTable:
        Type: AWS::EC2::RouteTable
        Properties:
          VpcId: !Ref vpc
          Tags:
            - Key: Name
              Value: !Join ['', [!Ref "AWS::StackName", "-private"]]
      privateRoute1:
        Type: AWS::EC2::Route
        Properties:
          RouteTableId: !Ref privateRouteTable
          DestinationCidrBlock: 0.0.0.0/0
          NatGatewayId: !Ref natGateway
      publicSubnetARouteTableAssociation:
        Type: AWS::EC2::SubnetRouteTableAssociation
        Properties:
          SubnetId: !Ref publicSubnetA
          RouteTableId: !Ref publicRouteTable
      publicSubnetBRouteTableAssociation:
        Type: AWS::EC2::SubnetRouteTableAssociation
        Properties:
          SubnetId: !Ref publicSubnetB
          RouteTableId: !Ref publicRouteTable
      privateSubnetARouteTableAssociation:
        Type: AWS::EC2::SubnetRouteTableAssociation
        Properties:
          SubnetId: !Ref privateSubnetA
          RouteTableId: !Ref privateRouteTable
      privateSubnetBRouteTableAssociation:
        Type: AWS::EC2::SubnetRouteTableAssociation
        Properties:
          SubnetId: !Ref privateSubnetB
          RouteTableId: !Ref privateRouteTable
    

    感谢迈克·阿特金森!

    【讨论】:

      猜你喜欢
      • 2021-01-14
      • 1970-01-01
      • 2020-08-27
      • 2016-12-29
      • 2021-07-14
      • 1970-01-01
      • 2021-12-18
      • 1970-01-01
      • 2017-01-31
      相关资源
      最近更新 更多