Skip to content

Instantly share code, notes, and snippets.

@igilham igilham/dynamodbcp.py
Last active Aug 28, 2018

Embed
What would you like to do?
Copy all data (by scanning) from one DynamoDB table to another
from __future__ import print_function
import argparse
import boto3
def copy_table(source, target):
dynamodb = boto3.resource("dynamodb")
source_table = dynamodb.Table(source)
target_table = dynamodb.Table(target)
records = source_table.scan()
with target_table.batch_writer() as batch:
for item in records["Items"]:
print('copying record {}', item)
batch.put_item(item)
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("source", help="Source table name")
parser.add_argument("target", help="target table name")
args = parser.parse_args()
print('copying items from {} to {}', args.source, args.target)
copy_table(args.source, args.target)
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.