安全地删除 cloudformation 堆栈中的 EBS 卷

Safe to delete an EBS volume in a cloudformation stack

我有一个 cloudformation 堆栈,我在其中创建了具有 2 个 EBS 卷的实例,1 个 main/root 和 1 个具有大量测试数据。附加测试数据的唯一原因是在堆栈创建后开始将数据加载到 hadoop 中。在那之后,我就没有必要保留那个 EBS 卷并为此付费了。但是,如果我手动删除它或使用 boto3 库,如果我尝试更新它或删除它,它会导致 cloudformation 堆栈出现问题吗?就像因为找不到资源而删除失败,或者如果我尝试用新标签更新堆栈,它会失败,因为它发现缺少资源。任何指导表示赞赏。

更新: 似乎 cloudformation 不会在堆栈资源中为我的卷创建资源,因为我在那里看不到它。但是,当我单击实例时,它有块设备 /dev/sda1,当我将鼠标悬停在它上面时,它会显示我在 cloudformation 中创建它的卷的 EBS ID。

我的 cloudformation 模板:

  ###################
  ### Master node ###
  ###################
  MasterNode:
    Type: AWS::EC2::Instance
    Properties:
      ImageId: !FindInMap [RegionMap, !Ref "AWS::Region", ami]
      InstanceType: r3.large
      KeyName: !FindInMap [RegionMap, !Ref "AWS::Region", key]
      SubnetId: !FindInMap [RegionMap, !Ref "AWS::Region", subnet]
      IamInstanceProfile: !Ref MasterNodeProfile
      SecurityGroupIds:
      - !Ref SecurityGroup
      - !Ref InternalSecurityGroup
      Tags:
      -
        Key: Name
        Value: Master for XYZ
      BlockDeviceMappings:
      - DeviceName: /dev/sda1
        Ebs:
          VolumeSize: 20
          DeleteOnTermination: True
          VolumeType: gp2
      UserData:
        Fn::Base64: !Sub |
           #!/bin/bash -xe
           yum install epel-release -y
           yum install python-pip -y
           pip install awscli

不是手动删除它,而是更新将删除资源的堆栈。如果您手动删除堆栈而不更新堆栈,您的堆栈 update/delete 将会失败。

发件人:I have manually deleted a resource that was created by CloudFormation. Updates to my stack are now failing—how can I resolve this issue?

If a resource was deleted because you no longer need it and you want to remove it from the stack, remove the resource and any references to it from your template, and then perform a stack update.

您可以在 EC2 属性上尝试 BlockDeviceMappings 来定义卷。 首先,你想要有两个卷,你可以添加这些代码。

"BlockDeviceMappings": [
                {
                    "DeviceName": "/dev/sd1",
                    "Ebs": {
                        "VolumeSize": "50",
                        "DeleteOnTermination": true
                    }
                }
            ]

您只需再添加一个,因为在创建EC2 实例时会自动创建根目录。 然后,如果你想删除它,删除那部分(上面的代码),并更新实例。 它将删除第二卷 (/dev/sd1)。