我已根据未运行的实例制作了清理ami id的脚本。 但我想删除这个脚本的功能,以清理启动配置表格AMI ID(实际上谁不存在)。
good_images = set([instance.image_id for instance in ec2.instances.all()])
#LaunchConfig in use AMI
client = boto3.client('autoscaling', region_name=region)
response = client.describe_launch_configurations()
ls_list=[]
for LC in response['LaunchConfigurations']:
(LC['ImageId'])
print ls_list
but its not working.
答案 0 :(得分:1)
您的代码:
for LC in response['LaunchConfigurations']:
(LC['ImageId'])
应该是:
for LC in response['LaunchConfigurations']:
(ls_list.append(LC['ImageId']))
答案 1 :(得分:0)
used_lc = []
all_lc = []
def used_launch_config():
for asg in client.describe_auto_scaling_groups()['AutoScalingGroups']:
launch_config_attached_with_asg = asg['LaunchConfigurationName']
used_lc.append(launch_config_attached_with_asg)
used_launch_config()
print used_lc
def all_spot_lc():
for launch_config in client.describe_launch_configurations(MaxRecords=100,)['LaunchConfigurations']:
lc = launch_config['LaunchConfigurationName']
if str(lc).startswith("string"):
all_lc.append(lc)
all_spot_lc()
print all_lc
我只是避免从AMI删除启动配置。 现在我比较使用或未使用它解决了问题。 我在以前的代码中做错了。
有办法增加最大记录