Created
December 18, 2019 12:05
-
-
Save ejdoh1/cda5063f10a8229e4bc071e0ab0c4678 to your computer and use it in GitHub Desktop.
Copy one AWS DynamoDB table to another
This file contains hidden or 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 | |
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