Dan
Dan

Reputation: 671

EC2 volume: how do I set it so that it WILL delete on termination?

I have an EC2 instance that I'd like to take a snapshot of, to use as an AMI for future spot instances. Because of the way I created volume for this instance, it is currently set to not delete upon termination.
I want it to delete on termination, so that I can use it for spot instances and not have residual volumes hanging around needing manual deletion.

I've combed AWS manual, stack exchange, google, etc and I can only find references to a 'delete on termination' flag, but no explanation of how to use it.

Upvotes: 13

Views: 11821

Answers (4)

Akshar Raaj
Akshar Raaj

Reputation: 15211

You can use AWS-CLI to do this:

The simplest way is to use modify-instance-attribute subcommand provided by aws ec2 command.

aws ec2 modify-instance-attribute --instance-id i-123ab12f --block-device-mappings file://~/some.json 

Content of file some.json should be:

[
    {
    "DeviceName": "/dev/sda1",
    "Ebs": {
      "DeleteOnTermination": true
      }
    }
]

Shameless Plug: If you regularly work with AWS, take this highly engaging AWS Quiz to check your AWS knowledge.

Upvotes: 2

w00t
w00t

Reputation: 676

Taking on what everybody else said, one line and without JSON encoding and ugly escapes:

modify-instance-attribute --instance-id $ID --block-device-mappings 'DeviceName=/dev/sdf,Ebs={DeleteOnTermination=true}'

Upvotes: 2

Doron
Doron

Reputation: 3256

Taking on what @akshar wrote, you can have it all in the same line, without the need for an additional json file:

 aws ec2 modify-instance-attribute --instance-id i-123abc45 --block-device-mappings "[{\"DeviceName\": \"/dev/sdf\",\"Ebs\":{\"DeleteOnTermination\":true}}]"

where /dev/sdf is the mount point in your instance

Upvotes: 12

FigmentEngine
FigmentEngine

Reputation: 511

enable delete on termination, for example http://itsecureadmin.com/2011/06/aws-instance-ebs-volume-delete-on-termination/

Upvotes: 2

Related Questions