SSM 的 BOTO3 服务员类型

BOTO3 Waiter Types for SSM

有人知道SSM可用的服务员类型吗? BOTO3 文档缺少一个部分。它说"See the waiters section",但没有这样的部分。

在线谷歌搜索没有多大帮助,因为这根本不是一个常见的话题。

您可以通过以下方式验证:

ssm = boto3.client('ssm')

print(ssm.waiter_names) 

这将打印出空数组:

[]

为了比较,对于ec2

ec2 = boto3.client('ec2')

print(ec2.waiter_names)

将给予(未全部显示):

['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 方法可能继承自某些父 class.

您可以试试这里的本地服务员:

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

目前只有command_executed个服务员

来自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
    }
)