Last active
August 28, 2018 09:31
-
-
Save igilham/add7cf2ce0d2dd3283d0f408d15c2708 to your computer and use it in GitHub Desktop.
Copy all data (by scanning) from one 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
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