Reputation: 711
I want to get a list of ec2 instances with no SSM installed.
I tried using boto3.describe_instance_information but getting an error.
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
Upvotes: 1
Views: 963
Reputation: 59906
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
Upvotes: 2