packetie
packetie

Reputation: 5069

Terminate an AWS EC2 instance without leaving a volume behind

I started an instance based on my AMI (based on Ubuntu 12.04 server) with the following command.

aws ec2 run-instances --image-id MY_AMI_ID --count 1 --instance-type t1.micro

What's surprising is, after I terminated the instance using the following command, it left an volume.

aws ec2 terminate-instances --instance-id MY_INSTANCE_ID

I would like to have the volume destroyed automatically, not sure if there is an easy option in the command line to do it.

Upvotes: 0

Views: 564

Answers (3)

packetie
packetie

Reputation: 5069

Found that http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/terminating-instances.html has an example

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

That solves my problem: now after an instance is terminated, it will not leave a volume behind.

Upvotes: 0

ma.tome
ma.tome

Reputation: 276

Your AMI probably has the option set to not terminate block devices. You can adjust this behavior in your AMI by using the "delete-on-termination" option in AWS Console or the AWS CLI ec2-register command:

http://docs.amazonwebservices.com/AWSEC2/latest/CommandLineReference/ApiReference-cmd-RegisterImage.html

Upvotes: 1

Naveen
Naveen

Reputation: 25

Have you attached the volume after launching the instance? As Amazon EC2 deletes all volumes that were attached during instance launch. Only volumes attached after instance is launched, will not be deleted.

Upvotes: 1

Related Questions