Set EC2 instance not to delete on terminate

If your EC2 instance is set to Delete on termination Yes and you want to modify that flag to No then you need to follow the below mentioned steps:

Precondition: Existing EC2 instance Delete on termination flag already set to Yes

We will be using the aws cli for modifying the Delete on termination setting. Below is the command to do the same:

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

In the above command, you just need to replace the instance id i.e i-023423423asda with your EC2 instance id. After running the above command, the instance will be set not to delete on terminate. You an verify the same by going into instance settings of your EC2.

In the above screenshot you can verify that that Delete on termination flag will be marked as No now.

If you want to know about how to install and configure AWS CLI on MAC then you can follow the following blog: How to install and configure AWS CLI on MAC