Py学习  »  Python

如何使用python boto3检查具有特定标记值的所有服务器的ssm连接状态

Binu • 4 年前 • 2319 次点击  

我想检查所有带有特定标签的服务器的ssm连接状态。我正在使用boto3模块获取连接状态,如下所示。

    # import statements not mentioned
    filter= [{'Name':'tag:Name', 'Values': ['Linux']}]
    def script(event, context):
      for each_ins in ec2_client.describe_instances(Filters=filter)['Reservations']:
        for inst_id in each_ins['Instances']:
            try:
                response = ssm_client.get_connection_status(Target=[inst_id['InstanceId']])
                pprint(inst_id['InstanceId'] + 'response')
            except Exception as e:
                print(e)

然而,get_connection_status函数只接受字符串,不接受列表。因此,我得到以下错误。我怎样才能摆脱这个?

{“ExecutionLog”:“参数验证失败: 参数目标的类型无效,值:['i-123xxxxxxxxx',类型:<类“列表”>,有效类型:<“str”类> "}

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/129319
文章 [ 1 ]  |  最新文章 4 年前
Marcin
Reply   •   1 楼
Marcin    4 年前

你正在使用 list ,而不是 string .应该是:

ssm_client.get_connection_status(Target=inst_id['InstanceId'])