Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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’>
"}

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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

ssm_client.get_connection_status(Target=inst_id['InstanceId'])
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading