amazon-web-servicesamazon-ec2aws-ebs

EC2-EBS root storage "Delete on Termination" set to True


I have created an EC2 Instance with "Delete on Termination" set to False at EBS Root storage. Now, I want to set it to True using AWS CLI.


Solution

  • To enable delete on termination for EBS:

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

    To enable delete on termination for an instance:

    aws ec2 modify-instance-attribute \
      --instance-id <...> \
      --instance-initiated-shutdown-behavior terminate