Skip to content

Instantly share code, notes, and snippets.

@ahammel
Created June 1, 2016 16:11
Show Gist options
  • Select an option

  • Save ahammel/254f07b593ed9d484bb06d9727b91ef9 to your computer and use it in GitHub Desktop.

Select an option

Save ahammel/254f07b593ed9d484bb06d9727b91ef9 to your computer and use it in GitHub Desktop.
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