Reputation: 25
so I'm scheduling an AWS python job (through AWS Glue Python shell) that is supposed to clone a MySQL RDS database (best way to take a snapshot and restore?) and perform sql queries on the database. I have the boto3 library on the Python Shell and an SQL Python Library I loaded. I have this code currently
import boto3
client = boto3.client('rds')
# Create a snapshot of the database
snapshot_response = client.create_db_snapshot(
DBSnapshotIdentifier='snapshot-identifier',
DBInstanceIdentifier='instance-db',
)
# Restore db from snapshot
restore_response = client.restore_db_instance_from_db_snapshot(
DBInstanceIdentifier = 'restored-db',
DBSnapshotIdentifier = 'snapshot-identifier',
)
# Code that will perform sql queries on the restored-db database.
However, the client.restore_db_instance_from_db_snapshot
fails because it says the snapshot is being created. So I understand that this means these calls are asynchronous. But I am not sure how to get this snapshot restore to work (either by making them synchronous - not a good idea?) or by some other way. Thanks for the help in advance :).
Upvotes: 1
Views: 3358
Reputation: 269540
You can use a waiter:
waiter = client.get_waiter('db_cluster_snapshot_available')
Polls
RDS.Client.describe_db_cluster_snapshots()
every 30 seconds until a successful state is reached. An error is returned after 60 failed checks.
See: class RDS.Waiter.DBClusterSnapshotAvailable
Upvotes: 3