Last active
August 29, 2015 14:20
-
-
Save prologic/4e1e39eba99205522c94 to your computer and use it in GitHub Desktop.
Hacked up script to restart an AWS Auto-Scaling Group
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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