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

倾然丶 夕夏残阳落幕 提交于 2019-12-08 15:51:42

问题


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.


回答1:


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




回答2:


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




回答3:


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
      }
    }
]



回答4:


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}'


来源:https://stackoverflow.com/questions/8138465/ec2-volume-how-do-i-set-it-so-that-it-will-delete-on-termination

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!