Skip to content

Instantly share code, notes, and snippets.

@coingraham
Created March 21, 2016 14:48
Show Gist options
  • Save coingraham/23cc6fe1aaeb60757161 to your computer and use it in GitHub Desktop.
Save coingraham/23cc6fe1aaeb60757161 to your computer and use it in GitHub Desktop.
Python - change ASG based on tag and current MinSize
import boto3
tagname = "Name"
tagvalue = "Value"
asg_client = boto3.client('autoscaling')
groups = asg_client.describe_auto_scaling_groups()
for group in groups[u'AutoScalingGroups']:
for tag in group[u'Tags']:
if tag[u'Key'] == tagname and \
tag[u'Value'] == tagvalue and \
group[u'MinSize'] > 0:
asg_client.update_auto_scaling_group(
AutoScalingGroupName=group[u'AutoScalingGroupName'],
MinSize=0, DesiredCapacity=0
)
for group in groups[u'AutoScalingGroups']:
for tag in group[u'Tags']:
if tag[u'Key'] == tagname and \
tag[u'Value'] == tagvalue and \
group[u'MinSize'] == 0:
asg_client.update_auto_scaling_group(
AutoScalingGroupName=group[u'AutoScalingGroupName'],
MinSize=1, DesiredCapacity=1
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment