【发布时间】:2017-09-22 06:34:11
【问题描述】:
我试图获取应用程序标记值为“CCC”的自动缩放组。
名单如下,
gweb
prd-dcc-eap-w2
gweb
prd-dcc-emc
gweb
prd-dcc-ems
CCC
dev-ccc-wer
CCC
dev-ccc-gbg
CCC
dev-ccc-wer
我在下面编写的脚本给出的输出包括一个没有 CCC 标签的 ASG。
#!/usr/bin/python
import boto3
client = boto3.client('autoscaling',region_name='us-west-2')
response = client.describe_auto_scaling_groups()
ccc_asg = []
all_asg = response['AutoScalingGroups']
for i in range(len(all_asg)):
all_tags = all_asg[i]['Tags']
for j in range(len(all_tags)):
if all_tags[j]['Key'] == 'Name':
asg_name = all_tags[j]['Value']
# print asg_name
if all_tags[j]['Key'] == 'Application':
app = all_tags[j]['Value']
# print app
if all_tags[j]['Value'] == 'CCC':
ccc_asg.append(asg_name)
print ccc_asg
我得到的输出如下,
['prd-dcc-ein-w2', 'dev-ccc-hap', 'dev-ccc-wfd', 'dev-ccc-sdf']
'prd-dcc-ein-w2' 是一个带有不同标签 'gweb' 的 asg。而 CCC ASG 列表中的最后一个(dev-ccc-msp-agt-asg) 也不见了。我需要如下输出,
dev-ccc-hap-sdf
dev-ccc-hap-gfh
dev-ccc-hap-tyu
dev-ccc-mso-hjk
我错过了什么吗?
【问题讨论】:
标签: python python-2.7 amazon-web-services boto3 autoscaling