Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/amazon-web-services/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Amazon web services 如何从AMI iD获取aws启动配置_Amazon Web Services_Amazon Ec2_Boto3 - Fatal编程技术网

Amazon web services 如何从AMI iD获取aws启动配置

Amazon web services 如何从AMI iD获取aws启动配置,amazon-web-services,amazon-ec2,boto3,Amazon Web Services,Amazon Ec2,Boto3,我已经创建了一个脚本,它根据未运行的实例清理ami id。 但我还想删除这个脚本的特性,以清除实际不存在的启动配置表单AMI 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_la

我已经创建了一个脚本,它根据未运行的实例清理ami id。 但我还想删除这个脚本的特性,以清除实际不存在的启动配置表单AMI

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.
您的代码:

for LC in response['LaunchConfigurations']:
    (LC['ImageId'])
应该是:

for LC in response['LaunchConfigurations']:
    (ls_list.append(LC['ImageId']))
我只是避免从AMI中删除启动配置。 现在我比较了用过还是没用过,它解决了这个问题。 我在以前的代码中做错了

有没有办法增加max记录


很抱歉,但不清楚你想做什么。请你再解释一下你想要达到的目标好吗?另外,您没有将结果添加到for循环中的ls_列表。@John我正在尝试删除基于AMI的旧启动配置。您的代码正在从所有实例获取AMI列表。然后它在启动配置中循环并检索相关的AMI,但不使用它做任何事情。请编辑并重写您的问题,以准确解释您想要做什么,或者您想要代码示例做什么。好的,我将更新此内容,但它不会打印任何启动确认..基于AMI ID。。有任何配置吗?
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