0

I have a cloudformation stack where I create instance with 2 EBS volumes, 1 main/root and 1 that has a lot of test data. The only reason to attach the test data is top load the data into hadoop in the beginning after stack creation. After that I have no point in keeping that EBS volume attached and paying money for it. But if I delete it manually or using boto3 library, will it cause problems with cloudformation stack later if I try to update it or delete it? Like deletion failed because it failed to find resources or if I try to update stack with a new tag, it will fail because it finds a resource missing. Any guidance is appreciated.

Update: Seems like cloudformation does not create a resource for my volume in stack resources because I cannot see it there. However when I click on instance, it has /dev/sda1 for block device and when I hover over it, it shows the EBS ID of the volume I created it with in my cloudformation.

My cloudformation template:

  ###################
  ### 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
alexfvolk
  • 1,810
  • 4
  • 20
  • 40

2 Answers2

2

You can try the BlockDeviceMappings on EC2 properties to define a volume. First, you want to have two volume, you can add these code.

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

You only have to add one more because the root is automatically created when EC2 instance is created. Then, if you want to delete it, remove that part (the code above), and update the instance. It will remove the second volume (/dev/sd1).

sin
  • 304
  • 3
  • 7
  • Since I am using jinja2 template, and this is automated, that is going to be pretty hard to do. I probably could do this: get the template through a boto3 request, save that file somewhere locally, and have some regex parsing take that piece out of the template, save it, and update stack with this new template. Yikes.. – alexfvolk Oct 24 '17 at 03:45
  • I am not really familiar with jinja, so I want to know is your jinja handle the whole template or just the EBS part? If it is only the EBS part, is it possible to create 2 different jinja template, the first one have 2 ebs and the second one only root? – sin Oct 24 '17 at 14:12
  • Can you add the yaml version? – Ramon Moraes Apr 11 '19 at 14:45
1

Instead of deleting it manually, update the stack which will delete the resource. Your stack update/delete will fail if you delete it manually and not update the stack.

From: 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.

helloV
  • 50,176
  • 7
  • 137
  • 145
  • Ah, sorry I just found out that the EBS volume is not even counted as a resource. I updated my original question. – alexfvolk Oct 24 '17 at 00:23