【问题标题】:AWS boto tags returning 0 instances when filtering by tag verified to exist当按验证存在的标签过滤时,AWS boto 标签返回 0 个实例
【发布时间】:2016-03-04 04:39:16
【问题描述】:

我正在使用 boto 返回带有 cluster_id 标记的实例,该标记是唯一标识集群的字符串 uuid。

我正在尝试使用 boto 返回带有该标签的实例,以确保集群已配置并准备就绪。因此,当带有 cluster_id 标签的单个实例的数量与预期数量匹配时,集群就准备好了,我的程序可以开始下一步的自动化。

这些实例在一个自动缩放组中,但我不确定为什么 boto 返回 0。我已经验证程序中的 cluster_id 是相同的,并且每个实例在 aws 中都是相同的。预订只返回 0。

Python 代码

ec2_conn = boto.connect_ec2(aws_access_key_id=aws_access_key_id,
                           aws_secret_access_key=aws_secret_access_key)
reservations = ec2_conn.get_all_instances(filters={"tag:cluster_id":str(cluster_id_tag)})
instances = [i for r in reservations for i in r.instances]
number_of_instances = len(instances)

cluster_id var in the program = 50a5fab0-e166-11e5-9ee9-a45e60e4b9b1

ASG 标签:

ElasticClientNode no                                           Yes
Name              elasticsearch-loading-master-nodes-cluster   Yes
a_or_b            a                                            Yes
cluster_id        50a5fab0-e166-11e5-9ee9-a45e60e4b9b1         Yes
version           1.0                                          Yes

实例标签

 ElasticClientNode         no                                            Show Column
 Name                      elasticsearch-loading-master-nodes-cluster    Hide Column
 a_or_b                    a                                             Show Column
 aws:autoscaling:groupName elasticsearch                                 Show Column
 cluster_id                50a5fab0-e166-11e5-9ee9-a45e60e4b9b1          Show Column
 version                   1.0                                           Show Column

【问题讨论】:

  • 你能用其他标签查询吗,例如Name
  • 它对我来说很好用。其他一些测试方法。在get_all_instances 之前打印cluster_id_tag 并查看值是否符合您的预期。

标签: python-2.7 amazon-web-services boto aws-sdk aws-cli


【解决方案1】:

答案是使用 connect_to_region 而不是 connect_ec2

    ec2_conn = boto.ec2.connect_to_region("us-west-2",
                                aws_access_key_id=aws_access_key_id,
                                aws_secret_access_key=aws_secret_access_key)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-05-25
    • 2013-10-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多