【问题标题】:BOTO3 Waiter Types for SSMSSM 的 BOTO3 服务员类型
【发布时间】:2020-06-18 21:01:07
【问题描述】:

有人知道 SSM 可用的服务员类型吗? BOTO3 文档缺少一节。上面写着"See the waiters section",但是没有这样的部分。

在网上搜索并没有多大帮助,因为它根本不是一个常见的话题。

【问题讨论】:

  • 如果文档中没有列出服务员,那么它就没有服务员。大多数服务都没有。
  • @jordanm 好的。我认为文档只是错过了该部分。无论如何,尽管有一个“get_waiter()”方法,我认为这个 SSM 服务没有任何服务员。

标签: python boto3 documentation aws-ssm


【解决方案1】:

您可以如下验证:

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 方法可能是从某个父类继承而来的。

【讨论】:

  • 谢谢!毕竟我在 SSM 文档页面上追逐鹅 :(
  • 仅供参考,从 boto3 1.14.47 开始,SSM 现在有一种服务员:``` print(ssm.waiter_names) >>>>> ['command_executed'] ```
  • @gye 感谢您告诉我。这非常有用。
【解决方案2】:

这里有一个你可以试试的本土服务员:

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

【讨论】:

    【解决方案3】:

    目前只有一个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
        }
    )
    

    【讨论】:

      猜你喜欢
      • 2021-10-20
      • 2020-10-05
      • 2021-09-28
      • 1970-01-01
      • 2020-09-27
      • 1970-01-01
      • 1970-01-01
      • 2018-08-03
      • 1970-01-01
      相关资源
      最近更新 更多