Last active
December 9, 2021 14:26
-
-
Save dallasmarlow/660952dbdd921dea8b8034a64ed8099f to your computer and use it in GitHub Desktop.
This file contains 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 os | |
import boto3 | |
BATCH_SIZE = 25 | |
REGION = 'us-west-2' | |
SRC_TABLE = os.environ['SRC'] | |
SNK_TABLE = os.environ['SNK'] | |
client = boto3.client('dynamodb', REGION) | |
tables = client.list_tables()['TableNames'] | |
for table in (SRC_TABLE, SNK_TABLE): | |
if table not in tables: | |
raise(Exception(f'DynamoDB table does not exist: {table}')) | |
for resp in client.get_paginator('scan').paginate(TableName=SRC_TABLE): | |
for n in range(0, len(resp['Items']), BATCH_SIZE): | |
item_group = resp['Items'][n:n+BATCH_SIZE] | |
req = { | |
SNK_TABLE: [ | |
{'PutRequest': {'Item': i}} | |
for i in item_group | |
] | |
} | |
client.batch_write_item(RequestItems=req) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment