简体   繁体   中英

AWS SSM check in ec2 instance

I want to get a list of ec2 instances with no SSM installed.

I tried using boto3.describe_instance_information but getting an error.

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

Did you read the documentation properly? As it accepts the Instance 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

This is a legacy method. We recommend that you don't use this method. Instead, use the InstanceInformationFilter action. The InstanceInformationFilter action enables you to return instance information by using tags that are specified as a key-value mapping.

If you do use this method, then you can't use the InstanceInformationFilter action. Using this method and the InstanceInformationFilter action causes an exception error.

Type: Array of InstanceInformationFilter objects

Array Members: Minimum number of 0 items.

Required: No

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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