使用boto3对具有特定应用程序标记的自动缩放组名称进行分页并列出
我已经在这里看到了建议的答案: 但是,它只处理前100个结果。它没有演示如何处理所有“页面”。我在一个大型AWS环境中工作,有两个问题使用boto3对具有特定应用程序标记的自动缩放组名称进行分页并列出,boto3,autoscaling,Boto3,Autoscaling,我已经在这里看到了建议的答案: 但是,它只处理前100个结果。它没有演示如何处理所有“页面”。我在一个大型AWS环境中工作,有两个问题 难道没有办法要求仅使用特定字符串标记asg,而不是解析环境中的所有内容吗 如果#1的答案是否定的-有人能帮助我了解如何对所有asg进行分页,直到所有asg都检查了相关标签吗 谢谢…这似乎有效。try/except块是必需的,否则无法跳出“while true”。总而言之,这感觉有点笨拙,但我不确定有没有更好的办法。我很乐意得到一些关于更优雅的方法的建议。我试图
谢谢…这似乎有效。try/except块是必需的,否则无法跳出“while true”。总而言之,这感觉有点笨拙,但我不确定有没有更好的办法。我很乐意得到一些关于更优雅的方法的建议。我试图通过打印访问过滤后的asg,但它只是在内存中留下了一个位置,所以考虑到我在最后期限,我加入了asg名称列表。当然有更好的方法。。。
def get_autoscale_groups(region):
client = boto3.client('autoscaling', region_name=region)
asg_name_list = []
while True:
paginator = client.get_paginator('describe_auto_scaling_groups')
page_iterator = paginator.paginate(
PaginationConfig={'PageSize': 100}
)
for page in page_iterator:
filtered_asgs = page_iterator.search(
'AutoScalingGroups[] | [?contains(Tags[?Key==`{}`].Value, `{}`)]'.format(
'SomeId', 'blah')
)
for asg in filtered_asgs:
asg_name_list.append(asg['AutoScalingGroupName'])
try:
marker = page['Marker']
print(marker)
except KeyError:
break
print(asg_name_list)
asg_client = session.client('autoscaling')
paginator = asg_client.get_paginator('describe_auto_scaling_groups')
asg_list = paginator.paginate()
for x in asg_list:
for asg in x['AutoScalingGroups']:
for tag in asg['Tags']:
if tag['Key'] == 'Solution':
print('ASG Name: '+ asg['AutoScalingGroupName'] + ' Tag: ' + tag['Value'])