2016年11月18日金曜日

aws-cli で Volume の Delete On Termination を操作する


EC2インスタンスを作成するときに、Delete On Termination を有効したい場合は、以下のように実行する。
aws ec2 run-instances --image-id ami-12345678 --count 1 --instance-type t2.micro --key-name default --security-groups test_group --block-device-mappings "[{\"DeviceName\": \"/dev/sda1\",\"Ebs\":{\"DeleteOnTermination\": \"true\"}}]"


EC2インスタンスを作成した後で有効したい場合は、以下のように実行する。
aws ec2 modify-instance-attribute --instance-id i-12345678 --block-device-mappings "[{\"DeviceName\": \"/dev/sda1\",\"Ebs\":{\"DeleteOnTermination\": true}}]"