Eliminating an EC2 Auto-Scaling Group

Delete KeySo the time has come to eliminate an Auto-Scaling Group running on your Amazon EC2 account, but you're getting the run-around from the API regarding the order of operations.  How the heck can we kill the instances without starting another, and then eliminate the triggers that will start new servers?

Luckily, it's not too difficult.

There are four commands that we need call with the Amazon Auto-Scaling API, and they must be done in a very particular order.  So here we go:

  1. as-update-auto-scaling-group {AS Group Name} —min-size 0
  2. as-set-desired-capacity {AS Group Name} —desired-capacity 0
  3. as-delete-auto-scaling-group {AS Group Name}
  4. as-delete-launch-config {AS Config Name}

First we change the Auto-Scaling Group to allow for zero instances to run, then set 0 as the desired capacity.  This will automatically terminate any instances that are running, which will give us the ability to delete the Auto-Scaling Group (which won't disappear so long as there are instances).  Once the Group is gone, we can delete the Auto-Scaling Launch Configuration.

One extra item that you might have to add is the region where your systems are running.  If the servers are in US-West, EU West, or Asia-Pacific, be sure to add the —region {Region Name} switch to the end of every API call.

Done and done.