[英]Boto3 Backup Waiters
我有一个脚本可以自动从 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 定义等待程序时,为什么此功能可用?
看起来不存在这样的服务员,但是您可以像这样创建自己的客户服务员:
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.