Skip to content

Instantly share code, notes, and snippets.

@Sam-Martin
Created May 15, 2019 13:24
Show Gist options
  • Save Sam-Martin/65da0d5605f9e5359bf40af2933fb076 to your computer and use it in GitHub Desktop.
Save Sam-Martin/65da0d5605f9e5359bf40af2933fb076 to your computer and use it in GitHub Desktop.
Download and Restore DynamoDB
aws dynamodb scan --table-name TABLE > export.json
import json
import boto3
dynamo = boto3.client('dynamodb')
TABLE_NAME = 'TABLE_NAME'
JSON_PATH = '/Users/USERNAME/git/GitHub/dynamodump/export.json'
with open(JSON_PATH, 'r') as file:
data = file.read()
parsed_file = json.loads(data)
for item_to_import in parsed_file['Items']:
print(f"Inserting {item_to_import['AccountId']['S']} - {item_to_import['CheckId']['S']}")
dynamo.batch_write_item(
RequestItems={
TABLE_NAME:[{
'PutRequest': {
'Item': item_to_import
}
}]
}
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment