Skip to content

Instantly share code, notes, and snippets.

@igilham
Last active August 28, 2018 09:31
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save igilham/add7cf2ce0d2dd3283d0f408d15c2708 to your computer and use it in GitHub Desktop.
Save igilham/add7cf2ce0d2dd3283d0f408d15c2708 to your computer and use it in GitHub Desktop.
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