【问题标题】:AWS CloudFormation: Unable to import resources of type SubnetRouteTableAssociation, VPCGatewayAttachment and RouteAWS CloudFormation:无法导入 SubnetRouteTableAssociation、VPCGatewayAttachment 和 Route 类型的资源
【发布时间】:2020-10-10 07:41:37
【问题描述】:

我正在尝试使用 CloudFormation 模板创建网络资源,但是当我导入模板时出现以下错误:

资源导入不支持以下资源类型:AWS::EC2::SubnetRouteTableAssociation,AWS::EC2::VPCGatewayAttachment,AWS::EC2::Route,AWS::EC2::Route

知道原因是什么。在我的 CF 模板的代码下方:

AWSTemplateFormatVersion: 2010-09-09
Resources:
TestDevVPC:
Type: 'AWS::EC2::VPC'
Properties:
  CidrBlock: 172.32.0.0/16
  Tags:
    - Key: Description
      Value: Created for Test development
PublicSubnet:
Type: 'AWS::EC2::Subnet'
Properties:
  CidrBlock: 172.32.1.0/24
  MapPublicIpOnLaunch: true
  VpcId: !Ref TestDevVPC
  Tags:
    - Key: Description
      Value: Public subnet for Test build
TestDevPublicRouteTable:
Type: 'AWS::EC2::RouteTable'
Properties:
  VpcId: !Ref TestDevVPC
  Tags:
    - Key: Description
      Value: public route table
TestDevInternetGateway:
Type: 'AWS::EC2::InternetGateway'
Properties:
  Tags:
    - Key: Description
      Value: Internet Gateway for Test Dev
TestDevIGVPCAttach:
Type: 'AWS::EC2::VPCGatewayAttachment'
Properties:
  InternetGatewayId: !Ref TestDevInternetGateway
  VpcId: !Ref TestDevVPC
TestDevSubnetRouteTableAssociation:
Type: 'AWS::EC2::SubnetRouteTableAssociation'
Properties:
  RouteTableId: TestDevPublicRouteTable
  SubnetId: PublicSubnet
Route1:
Type: 'AWS::EC2::Route'
Properties:
  DestinationCidrBlock: 172.32.0.0/16
  RouteTableId: !Ref TestDevPublicRouteTable
Route2:
Type: 'AWS::EC2::Route'
Properties:
  DestinationCidrBlock: 0.0.0.0/0
  RouteTableId: !Ref TestDevPublicRouteTable
  GatewayId: !Ref TestDevInternetGateway

【问题讨论】:

    标签: amazon-web-services amazon-cloudformation


    【解决方案1】:

    您的模板中几乎没有错误

    最重要的是,您不需要具有 172.32.0.0/16 本地规则的 Route1。这始终是默认创建的。

    TestDevSubnetRouteTableAssociation 的参数中也缺少 !Ref

    我修改了您的模板,以便现在可以部署。我没有检查它的功能,只检查它是否部署。

    您可以将其用作将来修改的基础。 :

    AWSTemplateFormatVersion: 2010-09-09
    
    Resources:
    
      TestDevVPC:
        Type: 'AWS::EC2::VPC'
        Properties:
          CidrBlock: 172.32.0.0/16
          Tags:
            - Key: Description
              Value: Created for Test development
    
      PublicSubnet:
        Type: 'AWS::EC2::Subnet'
        Properties:
          CidrBlock: 172.32.1.0/24
          MapPublicIpOnLaunch: true
          VpcId: !Ref TestDevVPC
          Tags:
            - Key: Description
              Value: Public subnet for Test build
    
      TestDevPublicRouteTable:
        Type: 'AWS::EC2::RouteTable'
        Properties:
          VpcId: !Ref TestDevVPC
          Tags:
            - Key: Description
              Value: public route table
    
      TestDevInternetGateway:
        Type: 'AWS::EC2::InternetGateway'
        Properties:
          Tags:
            - Key: Description
              Value: Internet Gateway for Test Dev
    
      TestDevIGVPCAttach:
        Type: 'AWS::EC2::VPCGatewayAttachment'
        Properties:
          InternetGatewayId: !Ref TestDevInternetGateway
          VpcId: !Ref TestDevVPC
    
    
      Route2:
        Type: 'AWS::EC2::Route'
        Properties:
          DestinationCidrBlock: 0.0.0.0/0
          RouteTableId: !Ref TestDevPublicRouteTable
          GatewayId: !Ref TestDevInternetGateway
    
      TestDevSubnetRouteTableAssociation:
        Type: 'AWS::EC2::SubnetRouteTableAssociation'
        Properties:
          RouteTableId: !Ref TestDevPublicRouteTable
          SubnetId: !Ref PublicSubnet
    
    

    【讨论】:

    • 感谢您指出这一点。我还发现我最初的错误不是由于我的模板中的错误,而是因为我在尝试创建堆栈时在控制台上选择了错误的选项。我选择“导入现有资源”而不是使用“使用新资源”
    • @BalkrishanNagpal 没问题。如果您觉得我的回答有帮助,一旦您对它感到满意,我们将不胜感激。
    猜你喜欢
    • 1970-01-01
    • 2022-11-16
    • 2021-02-28
    • 1970-01-01
    • 2020-04-10
    • 2021-10-15
    • 2019-10-23
    • 2018-10-25
    • 2020-12-12
    相关资源
    最近更新 更多