Skip to content

Instantly share code, notes, and snippets.

@dallasmarlow
Last active December 9, 2021 14:26
Show Gist options
  • Save dallasmarlow/660952dbdd921dea8b8034a64ed8099f to your computer and use it in GitHub Desktop.
Save dallasmarlow/660952dbdd921dea8b8034a64ed8099f to your computer and use it in GitHub Desktop.
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