BOTO3 Waiter Types for SSM

Question:

Does anyone know the available waiter types for SSM? The BOTO3 documentation is missing a section. It says “See the waiters section”, but there is no such a section.

Googling online didn’t help much, as it’s not a common topic at all.

Asked By: gye

||

Answers:

You can verify this as follows:

ssm = boto3.client('ssm')

print(ssm.waiter_names) 

This will print out empty array:

[]

For comparison, for ec2:

ec2 = boto3.client('ec2')

print(ec2.waiter_names)

Will give (not all shown):

['export_task_completed',
 'image_available',
 'image_exists',
 'instance_exists',
 'instance_running',
 'instance_status_ok',
 'instance_stopped',
 'subnet_available',
 'system_status_ok',
 'volume_available',
 'volume_deleted',
 'volume_in_use',
 'vpc_available',
 'vpc_exists',
 'vpc_peering_connection_deleted',
 'vpc_peering_connection_exists',
 'vpn_connection_available',
 'vpn_connection_deleted']

get_waiter method is probably inherited from some parent class.

Answered By: Marcin

Here’s a homegrown waiter you can try:

def send_command_wait_for_succes(commandid, instanceid):
    '''wait for success status, or end after 2 minutes'''
    cnt = 0
    while True:
        response = ssm_client.get_command_invocation(
            CommandId=commandid,
            InstanceId=instanceid)
        if response['Status'] != 'Success':
             time.sleep(5)
             cnt = cnt + 1
             if cnt == 24:
                return False
                break
        else:
            return True
            break

print(send_command_wait_for_succes(commandid, instanceid))
Answered By: Jonathan Leon

Currently there’s only a command_executed waiter.

From the boto3 docs:

import boto3

client = boto3.client('ssm')
waiter = client.get_waiter('command_executed')
waiter.wait(
    CommandId='string',
    InstanceId='string',
    PluginName='string',
    WaiterConfig={
        'Delay': 123,
        'MaxAttempts': 123
    }
)
Answered By: YoavBZ