简体   繁体   English

ec2实例中的AWS SSM检查

[英]AWS SSM check in ec2 instance

I want to get a list of ec2 instances with no SSM installed. 我想获取未安装SSM的ec2实例的列表。

I tried using boto3.describe_instance_information but getting an error. 我尝试使用boto3.describe_instance_information但收到错误。

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

Below is my code 下面是我的代码

import boto3


client = boto3.client('ssm')


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


print(response)

Error: 错误:

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]

Process finished with exit code 1 流程以退出代码1完成

Did you read the documentation properly? 您是否正确阅读了文档? As it accepts the Instance ID. 因为它接受实例ID。

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

so you have to pass ID 所以你必须通过身份证

import boto3


client = boto3.client('ssm')


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


print(response)

InstanceInformationFilterList InstanceInformationFilterList

This is a legacy method. 这是一种旧方法。 We recommend that you don't use this method. 我们建议您不要使用此方法。 Instead, use the InstanceInformationFilter action. 而是使用InstanceInformationFilter操作。 The InstanceInformationFilter action enables you to return instance information by using tags that are specified as a key-value mapping. InstanceInformationFilter操作使您可以使用指定为键值映射的标记来返回实例信息。

If you do use this method, then you can't use the InstanceInformationFilter action. 如果确实使用此方法,则不能使用InstanceInformationFilter操作。 Using this method and the InstanceInformationFilter action causes an exception error. 使用此方法和InstanceInformationFilter操作会导致异常错误。

Type: Array of InstanceInformationFilter objects

Array Members: Minimum number of 0 items.

Required: No

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM