两个后备服务员

2024-09-30 10:43:08 发布

您现在位置:Python中文网/ 问答频道 /正文

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

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

我正在使用函数start_restore_job()启动作业,然后describe_restore_job()查询CreatedResourceArn

启动还原作业后,我需要等待还原完成,以便查询CreatedResourceArn。这里的问题是AWS备份在其文档中没有定义任何等待者。有人知道怎么做吗

另外,在浏览文档时,我看到函数get_waiter()

enter image description here

为什么在没有为AWS备份定义Waiter时此功能可用


Tags: 函数文档https脚本comaws定义作业
1条回答
网友
1楼 · 发布于 2024-09-30 10:43:08

看起来服务生不存在,但您可以创建自己的客户服务生,如下所示:

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

相关问题 更多 >

    热门问题