Created
March 21, 2016 14:48
-
-
Save coingraham/23cc6fe1aaeb60757161 to your computer and use it in GitHub Desktop.
Python - change ASG based on tag and current MinSize
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
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