Automatically clean old detached EBS volumes

I have the following setup using Bamboo OnDemand:

  • An AMI containing everything I need to perform builds, derived from the Windows: EBS x86_64 (windows) (stock image).
  • An Elastic Instance Configuration which terminates all elastic instances at 8 PM.
  • An Elastic Instance Configuration which increases the number of elastic instances to 1 at 7 AM.

I start and stop the elastic instance created from my AMI in order to save costs on my Amazon bill. This works nicely, apart from the fact that old EBS volumes are not automatically removed.

Every week I now have a recurring manual task which requires me to log in to the Bamboo configuration panel, navigate to the disconnected instances and click the "Delete all" link at the right top side of the page to clean up those old EBS volumes.

If an elastic instance is terminated, I have no longer any need for the attached volume. Everything is contained within my AMI and I want to make sure I start from a fresh copy.

How can I automate this? I could not seem to find a setting which removes the old volume after the instance has been terminated. Should this be configured on the Amazon side, or on the Bamboo side?

2 answers

1 accepted

Accepted Answer
1 vote

Hi Jensen, 

 

I believe we have two reasons for this behaviour:

1 - Probably when an elastic instance is created, it get checked “DeleteOnTermination” is false. If so, it might be the reason. You can have more details checking this link: http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/terminating-instances.html#preserving-volumes-on-termination

 

2 - If everything is fine, maybe you might facing a bug. In this case, I advice you to open a ticket with amazon.  

However, a workaround you could  do in the meantime to avoid manual work is create a script to automatise the EBS’ deletions. For it, you need to install AWS API. You can get details on this link: https://aws.amazon.com/developertools/351

On this link you will find all EBS’ commands: http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ebs-api-cli-overview.html

And this another one you will find some examples about to delete the EBS: http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ebs-deleting-volume.html

For more commands related to AWS CLI, please have a look on this link: http://aws.amazon.com/cli/ 

 

I hope it helps :).

 

Regards, 

Renato Rudnicki

From what I can gather, the shutdown behavior is set to "terminate", which I believe is correct. There's also no termination protection enabled. The instance itself is correctly terminated, and disappears from the instance list. It's just the volumes that stay. I will try to manually terminate the instance tonight, and see what happens. That should help determine on who's end the potential bug may be.

OK, so the "DeleteOnTermination" flag is set to "False". I'll see during the course of the weekend if I can change this for my image.

0 votes

How is the EBS volume getting attached? Bamboo does it? Is it the root volume you're talking about or an external EBS?

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Thursday in Marketplace Apps

You + one app + a desert island...

Hi all! My name is Miles and I work on the Marketplace team. We’re looking for better ways to recommend and suggest apps that are truly crowd favorites, so of course we wanted to poll the Community. ...

130 views 3 4
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you