在python中使用boto3服务程序时出错



我试图使用下面的python脚本,但当我试图执行该脚本时,我遇到了一个错误:

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

修复了代码中的几个拼写错误,并将您切换到DB实例服务生而不是DB集群服务生。我还把服务员的时间增加到了30分钟,因为RDS恢复可以说很长时间。

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

最新更新