Created
August 1, 2019 11:32
-
-
Save andypols/0ad71256fbdd63a636a39fbf9d74ab87 to your computer and use it in GitHub Desktop.
Python script to migrate a dynamo DB table from one AWS account to another
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import boto3 | |
table_name = 'vinterest-test' | |
source = boto3.resource('dynamodb', | |
aws_access_key_id='<TODO>', | |
aws_secret_access_key='<TODO>' | |
) | |
source_table = source.Table(table_name) | |
dest = boto3.resource('dynamodb', | |
aws_access_key_id='<TODO>', | |
aws_secret_access_key='<TODO>', | |
aws_session_token='<TODO>', | |
) | |
dest_table = dest.Table(table_name) | |
response = source_table.scan(TableName=table_name, Select='ALL_ATTRIBUTES') | |
count = 0 | |
def process_items(count, items): | |
for row in items: | |
count += 1 | |
print('%s: %s' % (count, row)) | |
dest_table.put_item(Item=row) | |
return count | |
count = process_items(count, response['Items']) | |
while 'LastEvaluatedKey' in response: | |
response = source_table.scan(TableName=table_name, Select='ALL_ATTRIBUTES', ExclusiveStartKey=response['LastEvaluatedKey']) | |
count = process_items(count, response['Items']) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment