简体   繁体   中英

Getting an error while using the boto3 waiter in python

I am trying to use the below python script, but when I try to execute the script I am getting an error:

botocore.errorfactory.InvalidDBSnapshotStateFault: An error occurred (InvalidDBSnapshotState) when calling the RestoreDBInstanceFromDBSnapshot operation: DBSnapshot must have state available but actually has creating

#!/usr/bin/python
import boto3
import botocore
client = boto3.client('rds')
# Create a snapshot of the database
snapshot_response = client.create_db_snapshot(
    DBSnapshotIdentifier='test-1-2021',
    DBInstanceIdentifier='test-1',
)
waiter = client.get_waiter('db_cluster_snapshot_avaialbe')

# Restore db from snapshot
restore_response = client.restore_db_instance_from_db_snapshot (
    DBInstanceIdentifier='test-stg',
    DBSnapshotIdentifier='test-1-2021',
)

Fixed a couple typos with your code and switched you to the DB instance waiter instead of the DB cluster waiter. I also increased the time on the waiter to 30 minutes since RDS restores can talk a long time.

import boto3

client = boto3.client('rds')

# Create a snapshot of the database
snapshot_response = client.create_db_snapshot(
    DBSnapshotIdentifier='test-1-2021',
    DBInstanceIdentifier='test-1',
)
waiter = client.get_waiter('db_snapshot_available')

waiter.wait(
    DBInstanceIdentifier='test-1',
    DBSnapshotIdentifier='test-1-2021',
    WaiterConfig={
        'Delay': 60,
        'MaxAttempts': 30
    }
)

# Restore db from snapshot
restore_response = client.restore_db_instance_from_db_snapshot (
    DBInstanceIdentifier='test-stg',
    DBSnapshotIdentifier='test-1-2021',
)

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