Search code examples
amazon-web-servicesamazon-ec2

Preserving volume of cloned AWS EC2 instance


I have cloned an AWS EC2 instance and attached it to an existing volume (of another EC2 instance). Now I want to terminate the cloned instance but I want to keep the volume.

How do I make sure that the volume won't be deleted after I terminate the cloned instance?


Solution

  • If you've cloned an EC2 instance and need to verify the Delete on Termination setting, follow these steps:

    • Navigate to the EC2 console.
    • Select the cloned EC2 instance.
    • Go to the Storage tab and confirm the "Delete on Termination" setting.

    If it is set to No, deleting the cloned EC2 instance will not delete the associated volume. However, if it is set to Yes, modifying Delete on Termination for a running server is only possible through AWS CLI. The AWS Console allows this setting to be adjusted only during the server's launch.

    To modify Delete on Termination using AWS CLI:

    aws ec2 modify-instance-attribute --instance-id <instance-id> --block-device-mappings file://mapping.json
    

    In mapping.json, specify the device name, for example /dev/sda1 or /dev/xvda, and for --DeleteOnTermination, specify false.

    [
      {
        "DeviceName": "device_name",
        "Ebs": {
          "DeleteOnTermination": false
        }
      }
    ]
    

    Reference Link:- https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/terminate-instances-considerations.html