Skip to content
Advertisement

How to check the ssm connection status of all the servers with a specific tag value using python boto3

I wanted to check the ssm connection status of all the servers with a specific tag. I am making use of the boto3 module get_connection_status as follows.

    # 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)

However get_connection_status functions accepts only strings and not list. Hence I am getting the below error. How can I get rid of this?

{“ExecutionLog”:”Parameter validation failed: Invalid type for parameter Target, value: [‘i-123xxxxxxxxx’], type: <class ‘list’>, valid types: <class ‘str’> “}

Advertisement

Answer

You are using a list, not a string. It should be:

ssm_client.get_connection_status(Target=inst_id['InstanceId'])
2 People found this is helpful
Advertisement