Skip to content

Instantly share code, notes, and snippets.

@prologic
Last active August 29, 2015 14:20
Show Gist options
  • Save prologic/4e1e39eba99205522c94 to your computer and use it in GitHub Desktop.
Save prologic/4e1e39eba99205522c94 to your computer and use it in GitHub Desktop.
Hacked up script to restart an AWS Auto-Scaling Group
#!/usr/bin/env python
import sys
from time import sleep
from functools import partial
import boto.ec2.autoscale
name = sys.argv[1]
autoscale = boto.ec2.autoscale.connect_to_region("ap-southeast-2")
group = autoscale.get_all_groups([name])[0]
desired, min, max = map(partial(getattr, group), ("desired_capacity", "min_size", "max_size",))
group.desired_capacity = 0
group.min_size = 0
group.max_size = 0
group.update()
instances = group.instances
while instances:
group = autoscale.get_all_groups([name])[0]
instances = group.instances
sleep(5)
group.desired_capacity = desired
group.min_size = min
group.max_size = max
group.update()
instances = group.instances
while not all((instance.lifecycle_state == "InService" for instance in instances)):
group = autoscale.get_all_groups([name])[0]
instances = group.instances
sleep(5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment