Skip to content

Instantly share code, notes, and snippets.

@ejdoh1
Created December 18, 2019 12:05
Show Gist options
  • Save ejdoh1/cda5063f10a8229e4bc071e0ab0c4678 to your computer and use it in GitHub Desktop.
Save ejdoh1/cda5063f10a8229e4bc071e0ab0c4678 to your computer and use it in GitHub Desktop.
Copy one AWS DynamoDB table to another
import boto3
ddb = boto3.Session(region_name='REPLACE_ME',profile_name='REPLACE_ME').resource('dynamodb')
tbl_from = ddb.Table('REPLACE_ME')
tbl_to = ddb.Table('REPLACE_ME')
r = tbl_from.scan()
d = r['Items']
while 'LastEvaluatedKey' in r:
r = tbl_from.scan(ExclusiveStartKey=r['LastEvaluatedKey'])
d = d + r['Items']
with tbl_to.batch_writer() as b:
for i in d:
b.put_item(Item=i)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment