Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
DynamoDB Backup and Migration
import time
import boto3
dynamodb = boto3.client('dynamodb')
source_table_name = "customerTable" # Or whatever your source table name is
dest_table_name = "customerTable-dev" # This should be an empty table - the script will delete it first
backup_name = source_table_name + "backupMigration" # Or any other backup name
# Create the backup
response = dynamodb.create_backup(
TableName=source_table_name,
BackupName=backup_name
)
# Get the backup ARN From the response
backup_arn = response["BackupDetails"]["BackupArn"]
dynamodb.delete_table(
TableName=dest_table_name
)
while True:
try:
dynamodb.describe_table(
TableName=dest_table_name,
)
time.sleep(5)
except dynamodb.exceptions.ResourceNotFoundException:
dynamodb.restore_table_from_backup(
TargetTableName=dest_table_name,
BackupArn=backup_arn
)
break
except dynamodb.exceptions.ResourceInUseException:
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.