【问题标题】:Can't create resource in Cloudformation as name is already taken由于名称已被占用,因此无法在 Cloudformation 中创建资源
【发布时间】:2020-12-09 15:53:00
【问题描述】:

我正在尝试通过 cloudformation 设置技术堆栈。我不得不多次部署它,因为它很难拼凑在一起,而且目前只做一件事。我定义了以下资源,我经常需要重命名,因为当我删除我的堆栈然后重新创建它时,我收到一条错误消息,指出该资源已经以该名称存在。这尤其令人困惑,因为我在 AWS 控制台的任何地方都找不到列出的资源(我在正确的区域)。请参阅下文,我们将不胜感激。

谢谢,

埃里克

  DBSecurityGroupTwentyFour:
Type: AWS::EC2::SecurityGroup
Properties:
  GroupName: DBSecurityGroupTwentyFour
  GroupDescription: Security group for NGINX container
  SecurityGroupIngress:
    - IpProtocol: tcp
      FromPort: 3306
      ToPort: 3306
      CidrIp: 0.0.0.0/0

【问题讨论】:

    标签: amazon-web-services amazon-cloudformation


    【解决方案1】:

    在这种情况下,我通常在字段中添加堆栈名称以保持唯一性。

    例子:

      DBSecurityGroupTwentyFour:
        Type: AWS::EC2::SecurityGroup
        Properties:
          GroupName: !Sub ${AWS::StackName}DBSecurityGroupTwentyFour
          GroupDescription: !Sub ${AWS::StackName} - Security group for NGINX container
          SecurityGroupIngress:
            - IpProtocol: tcp
              FromPort: 3306
              ToPort: 3306
              CidrIp: 0.0.0.0/0
    

    【讨论】:

      【解决方案2】:

      你也可以跳过 GroupName: DBSecurityGroupTwentyFour:

      DBSecurityGroupTwentyFour:
        Type: AWS::EC2::SecurityGroup
        Properties:
          GroupDescription: Security group for NGINX container
          SecurityGroupIngress:
            - IpProtocol: tcp
              FromPort: 3306
              ToPort: 3306
              CidrIp: 0.0.0.0/0
      

      这样 CFN 将为 SG自动生成名称,您不必担心命名。

      【讨论】:

        猜你喜欢
        • 2020-12-19
        • 2021-06-12
        • 2021-01-16
        • 2020-09-30
        • 2019-08-21
        • 2020-03-31
        • 2020-01-22
        • 2019-08-31
        • 1970-01-01
        相关资源
        最近更新 更多