简体   繁体   English

Boto3 备份服务员

[英]Boto3 Backup Waiters

I have a script that automates restore jobs from AWS Backups.我有一个脚本可以自动从 AWS Backups 还原作业。

I am taking guidance from this documentation of boto3: https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/backup.html我正在从 boto3 的这个文档中获取指导​​: https ://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/backup.html

I am using the function start_restore_job() to start a job and then describe_restore_job() to query the CreatedResourceArn我正在使用函数start_restore_job()来开始一项工作,然后describe_restore_job()来查询CreatedResourceArn

After a restore job is launched, I need to wait for the restore to be completed so that i can query the CreatedResourceArn .启动还原作业后,我需要等待还原完成,以便查询CreatedResourceArn The issue here is that AWS Backup doesn't have any waiters defined in its documentation.这里的问题是 AWS Backup 的文档中没有定义任何服务员。 Does someone know how to do this?有人知道怎么做吗?

Also, going through the docs, I see the function get_waiter() :另外,通过文档,我看到了函数get_waiter()

在此处输入图片说明

Why is this function available when there is no waiters defined for AWS Backup ?当没有为 AWS Backup 定义等待程序时,为什么此功能可用?

Looks like a waiter doesn't exist for this, but you can create your own customer waiters like this:看起来不存在这样的服务员,但是您可以像这样创建自己的客户服务员:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM