【问题标题】:AWS SSM check in ec2 instanceAWS SSM 签入 ec2 实例
【发布时间】:2019-09-12 13:01:38
【问题描述】:

我想获取未安装 SSM 的 ec2 实例列表。

我尝试使用 boto3.describe_instance_information 但出现错误。

https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/ssm.html#SSM.Client.describe_instance_information

下面是我的代码

import boto3


client = boto3.client('ssm')


response = client.describe_instance_information(
    InstanceInformationFilterList=[
        {
            'key': 'i-0187655667fghj',
            'valueSet': [
                'AgentVersion',
                'InstanceIds'
            ]
        }
    ]
)


print(response)

错误:

Traceback (most recent call last):
  File "ssm.py", line 13, in <module>
    'InstanceIds'
  File "/Library/Python/2.7/site-packages/botocore/client.py", line 357, in _api_call
    return self._make_api_call(operation_name, kwargs)
  File "/Library/Python/2.7/site-packages/botocore/client.py", line 661, in _make_api_call
    raise error_class(parsed_response, operation_name)

botocore.exceptions.ClientError: An error occurred (ValidationException) when calling the DescribeInstanceInformation operation: 1 validation error detected: Value 'i-0187655667fghj' at 'instanceInformationFilterList.1.member.key' failed to satisfy constraint: Member must satisfy enum value set: [ActivationIds, InstanceIds, PingStatus, PlatformTypes, ResourceType, IamRole, AssociationStatus, AgentVersion]

进程以退出代码 1 结束

【问题讨论】:

    标签: python amazon-web-services boto3


    【解决方案1】:

    您是否正确阅读了文档?因为它接受实例 ID。

    {
                'key': 'InstanceIds'|'AgentVersion'|'PingStatus'|'PlatformTypes'|'ActivationIds'|'IamRole'|'ResourceType'|'AssociationStatus',
                'valueSet': [
                    'string',
                ]
            }
    

    所以你必须传递 ID

    import boto3
    
    
    client = boto3.client('ssm')
    
    
    response = client.describe_instance_information(
        InstanceInformationFilterList=[
            {
                'key': 'InstanceIds',
                'valueSet': [
                    'i-0187655667fghj'
                ]
            }
        ]
    )
    
    
    print(response)
    

    InstanceInformationFilterList

    这是一种传统方法。我们建议您不要使用此方法。 相反,请使用 InstanceInformationFilter 操作。这 InstanceInformationFilter 操作使您能够返回实例 通过使用指定为键值映射的标签来获取信息。

    如果你确实使用了这个方法,那么你就不能使用 InstanceInformationFilter 操作。使用这种方法和 InstanceInformationFilter 操作导致异常错误。

    Type: Array of InstanceInformationFilter objects
    
    Array Members: Minimum number of 0 items.
    
    Required: No
    

    【讨论】:

      猜你喜欢
      • 2019-08-25
      • 2020-02-25
      • 2021-10-12
      • 2021-10-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-06-18
      • 2020-03-16
      相关资源
      最近更新 更多