How to change Delete on Termination setting to False EC2 and EBS

By default, the root EBS volume is set to delete on termination. We can disable this setting using the AWS CLI.

Suppose you have an EC2 instance with ID i-1234567890abcdef0 and you want to ensure that the root volume (/dev/xvda) persists even when the instance is terminated. You would create a mapping.json file with the following content:

[
  {
    "DeviceName": "/dev/xvda",
    "Ebs": {
      "DeleteOnTermination": false
    }
  }
]

Then, execute the command:

aws ec2 modify-instance-attribute --instance-id i-1234567890abcdef0 --block-device-mappings file://mapping.json

This will modify the instance attribute to set "Delete on Termination" to false for the root EBS volume (/dev/xvda) of the specified instance.

0
Subscribe to my newsletter

Read articles from PEDA RAYUDU DOLA directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

PEDA RAYUDU DOLA
PEDA RAYUDU DOLA