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

2019-06-15 17:47发布

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.

4条回答
一纸荒年 Trace。
2楼-- · 2019-06-15 18:26

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
      }
    }
]
查看更多
该账号已被封号
3楼-- · 2019-06-15 18:35

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

查看更多
成全新的幸福
4楼-- · 2019-06-15 18:41

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}'
查看更多
混吃等死
5楼-- · 2019-06-15 18:50
登录 后发表回答