Created
June 1, 2016 16:11
-
-
Save ahammel/254f07b593ed9d484bb06d9727b91ef9 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| client = boto3.client("autoscaling") | |
| asg_paginator = client.paginator("describe_auto_scaling_groups") | |
| used_launch_configs = set([ | |
| asg["LaunchConfigurationName"] | |
| for page in asg_paginator.paginate() | |
| for asg in page["AutoScalingGroups"]]) | |
| # what if somebody makes a buch of AGS at this point in the execution? | |
| launch_config_paginator = client.paginator('describe_launch_configurations') | |
| for page in launch_config_paginator.paginate(): | |
| for launch_config in page["LaunchConfigurations"]: | |
| if launch_config["LaunchConfigurationName"] not in used_launch_configs: | |
| try: | |
| client.delete_launch_configuration( | |
| LaunchConfigurationName=launch_config["LaunchConfigurationName"]) | |
| except LaunchConfigrationIsAttachedToSomething: | |
| bail() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment