Keep an Amazon EBS root volume after an Amazon EC2 instance terminates - Amazon Elastic Compute Cloud

Keep an Amazon EBS root volume after an Amazon EC2 instance terminates

By default, the Amazon EBS root volume for an instance is deleted when the instance terminates. You can change the default behavior to ensure that an Amazon EBS root volume persists after the instance terminates. To change the default behavior, set the DeleteOnTermination attribute to false. You can do so either at instance launch or later on.

Configure the root volume to persist during instance launch

You can configure the root volume to persist when you launch an instance.

Console
To configure the root volume to persist when you launch an instance using the console
  1. Open the Amazon EC2 console at https://console.aws.amazon.com/ec2/.

  2. In the navigation pane, choose Instances and then choose Launch instances.

  3. Choose an Amazon Machine Image (AMI), choose and instance type, choose a key pair, and configure your network settings.

  4. For Configure storage, choose Advanced.

  5. Expand the root volume.

  6. For Delete on termination, choose No.

  7. When you are finished configuring your instance, choose Launch instance.

AWS CLI
To configure the root volume to persist when you launch an instance using the AWS CLI

Use the run-instances command and include a block device mapping that sets the DeleteOnTermination attribute to false.

aws ec2 run-instances --block-device-mappings file://mapping.json ...other parameters...

Specify the following in mapping.json.

[ { "DeviceName": "/dev/sda1", "Ebs": { "DeleteOnTermination": false } } ]
Tools for Windows PowerShell
To configure the root volume to persist when you launch an instance using the Tools for Windows PowerShell

Use the New-EC2Instance command and include a block device mapping that sets the DeleteOnTermination attribute to false.

C:\> $ebs = New-Object Amazon.EC2.Model.EbsBlockDevice C:\> $ebs.DeleteOnTermination = $false C:\> $bdm = New-Object Amazon.EC2.Model.BlockDeviceMapping C:\> $bdm.DeviceName = "dev/xvda" C:\> $bdm.Ebs = $ebs C:\> New-EC2Instance -ImageId ami-0abcdef1234567890 -BlockDeviceMapping $bdm ...other parameters...

Configure the root volume to persist for an existing instance

You can configure the root volume to persist for a running instance. Note that you can't complete this task using the Amazon EC2 console.

AWS CLI
To configure the root volume to persist for an existing instance using the AWS CLI

Use the modify-instance-attribute command with a block device mapping that sets the DeleteOnTermination attribute to false.

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

Specify the following in mapping.json.

[ { "DeviceName": "/dev/xvda", "Ebs": { "DeleteOnTermination": false } } ]
Tools for Windows PowerShell
To configure the root volume to persist for an existing instance using the AWS Tools for Windows PowerShell

Use the Edit-EC2InstanceAttribute command with a block device mapping that sets the DeleteOnTermination attribute to false.

C:\> $ebs = New-Object Amazon.EC2.Model.EbsInstanceBlockDeviceSpecification C:\> $ebs.DeleteOnTermination = $false C:\> $bdm = New-Object Amazon.EC2.Model.InstanceBlockDeviceMappingSpecification C:\> $bdm.DeviceName = "/dev/xvda" C:\> $bdm.Ebs = $ebs C:\> Edit-EC2InstanceAttribute -InstanceId i-1234567890abcdef0 -BlockDeviceMapping $bdm

Confirm that a root volume is configured to persist

You can confirm that a root volume is configured to persist using the Amazon EC2 console or the command line tools.

Console
To confirm that a root volume is configured to persist using the Amazon EC2 console
  1. Open the Amazon EC2 console at https://console.aws.amazon.com/ec2/.

  2. In the navigation pane, choose Instances and then select the instance.

  3. In the Storage tab, under Block devices, locate the entry for the root volume. If Delete on termination is No, the volume is configured to persist.

AWS CLI
To confirm that a root volume is configured to persist using the AWS CLI

Use the describe-instances command and verify that the DeleteOnTermination attribute in the BlockDeviceMappings response element is set to false.

aws ec2 describe-instances --instance-id i-1234567890abcdef0
... "BlockDeviceMappings": [ { "DeviceName": "/dev/sda1", "Ebs": { "Status": "attached", "DeleteOnTermination": false, "VolumeId": "vol-1234567890abcdef0", "AttachTime": "2013-07-19T02:42:39.000Z" } } ...
Tools for Windows PowerShell
To confirm that a root volume is configured to persist using the AWS Tools for Windows PowerShell

Use the Get-EC2Instance and verify that the DeleteOnTermination attribute in the BlockDeviceMappings response element is set to false.

C:\> (Get-EC2Instance -InstanceId i-i-1234567890abcdef0).Instances.BlockDeviceMappings.Ebs