Boto3 后备服务员

Boto3 Backup Waiters

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

我正在从 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 定义服务员的情况下可以使用此功能?

看起来好像没有服务员,但您可以像这样创建自己的客户服务员:

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