【问题标题】:Boto3 Backup WaitersBoto3 备份服务员
【发布时间】:2021-09-28 22:33:30
【问题描述】:

我有一个脚本可以自动从 AWS Backups 恢复作业。

我正在从 boto3 的文档中获取指导​​:https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/backup.html

我正在使用函数start_restore_job() 开始工作,然后describe_restore_job() 查询CreatedResourceArn

启动恢复作业后,我需要等待恢复完成,以便查询 CreatedResourceArn。这里的问题是 AWS Backup 在其文档中没有定义任何服务员。有人知道怎么做吗?

另外,通过文档,我看到了函数get_waiter()

为什么在没有为 AWS Backup 定义服务员的情况下可以使用此功能?

【问题讨论】:

  • 我怀疑它可能是在父客户端类中定义的,因此包含在每个服务中。
  • 所以没有办法等待恢复工作完成?

标签: python python-3.x amazon-web-services boto3 aws-backup


【解决方案1】:

看起来服务员不存在,但您可以像这样创建自己的客户服务员:

import boto3
from botocore.waiter import WaiterModel
from botocore.waiter import create_waiter_with_client

client = boto3.client('backup')
waiter_name = "BackupCompleted"
waiter_config = {
    "version": 2,
    "waiters": {
        "BackupCompleted": {
            "operation": "DescribeRestoreJob",
            "delay": 60, # Number of seconds to delay
            "maxAttempts": 5, # Max attempts before failure
            "acceptors": [
                {
                    "matcher": "path",
                    "expected": "COMPLETED",
                    "argument": "Status",
                    "state": "success"
                },
                {
                    "matcher": "path",
                    "expected": "ABORTED",
                    "argument": "Status",
                    "state": "failure"
                },
                {
                    "matcher": "path",
                    "expected": "FAILED",
                    "argument": "Status",
                    "state": "failure"
                }
            ]
        }
    }
}
waiter_model = WaiterModel(waiter_config)
backup_waiter = create_waiter_with_client(waiter_name, waiter_model, client)

backup_waiter.wait(RestoreJobId='MyRestoreJobId')

【讨论】:

  • 正是我需要的!谢谢老哥
猜你喜欢
  • 2020-10-05
  • 1970-01-01
  • 1970-01-01
  • 2020-09-27
  • 2021-04-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多