How to modify “Delete on Termination” attribute of an EC2 Instance from AWS CLI

By default the ‘DeleteOnTermination’ attribute of an EBS backed EC2 Instance is ‘True’. Root volume can be preserved on termination by changing the ‘DeleteOnTermination’ attribute to false as below :

aws ec2 modify-instance-attribute --instance-id INSTANCEID --block-device-mappings "[{\"DeviceName\": \"/dev/sda1\",\"Ebs\":{\"DeleteOnTermination\":false}}]"

See also  How to change the distribution style of a table in Redshift database