1

我有一个脚本可以自动从 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 定义服务员的情况下可以使用此功能?

4

1 回答 1

2

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

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')
于 2021-07-23T13:22:21.673 回答