简体   繁体   中英

Boto3 Backup Waiters

I have a script that automates restore jobs from AWS Backups.

I am taking guidance from this documentation of 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

After a restore job is launched, I need to wait for the restore to be completed so that i can query the CreatedResourceArn . The issue here is that AWS Backup doesn't have any waiters defined in its documentation. Does someone know how to do this?

Also, going through the docs, I see the function get_waiter() :

在此处输入图片说明

Why is this function available when there is no waiters defined for 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')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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