When launching an AWS EC2 instance, you can specify whether a EBS volume will be deleted when the instance is terminated. The setting is “Delete On Termination” and it’s on by default.
Once the instance is launched, viewing or modifying this “Delete On Termination” setting is not obvious. This post is to document how I do it.
View “Delete On Termination” Setting on AWS EBS Volume
There are two ways:
- Use EC2 management console
- Click on Instances and select the instance
- Under Description tab,scroll down to “Block devices"
- Click on the device name to show the “Delete on termination” setting on the pop-up window
- Use AWS CLI
- Get the instance ID
- $ aws ec2 describe-instances --query 'Reservations[*].Instances[*].InstanceId' --output text
- Query the setting
- aws ec2 describe-instances --filter "Name=instance-id,Values=i-0d0a326ab6691cf24" --query 'Reservations[*].Instances[*].BlockDeviceMappings[*].Ebs.DeleteOnTermination'
- Get the instance ID
Modify “Delete On Termination” Setting on AWS EBS Volume
I cannot find a way to modify this setting on EC2 management console. It looks AWS CLI is the only way. Here is the CLI.
aws ec2 modify-instance-attribute --instance-id i-0d0a326ab6691cf24 --block-device-mappings file://./change.DeleteOnTermination.json
The json file format is below. Update the DeviceName to match the EBS volume that you wan to modify
[
{
"DeviceName": "/dev/xvda",
"Ebs": {
"DeleteOnTermination": false
}
}
]
After executing the CLI, refresh the management console and click on the volume name under the instance description to verify the setting has been modified.
No comments:
Post a Comment