DEV Community

Arun Kumar for AWS Community Builders

Posted on

Cross Account DynamoDB Table Replication

Objective

This is to migrate (one-time replication) DynamoDB table between different AWS accounts.

1

Implementation Steps

Prerequisite: npm installed

a. Download the scripts from below repo “core-dynamodb-replication”
akrockz/core-dynamodb-replication

This module will allow you to copy data from one table to another using very simple API, Support cross zone copying and…github.com

b. In “execute.js”, update access key details for source and destination AWS accounts (IAM User: dynamodb-ce).

c. In “execute.js”, update DynamoDb table names for source and destination AWS account.

copy({
source: {
tableName: 'demo-dynamodb-poc-old-dynamodb', // required
config: sourceAWSConfig // optional , leave blank to use globalAWSConfig
},
destination: {
tableName: 'demo-dynamodb-poc-new-dynamodb', // required
config: destinationAWSConfig // optional , leave blank to use globalAWSConfig
},
Enter fullscreen mode Exit fullscreen mode

d. Before executing the command, verify the source and destination DynamoDB and check for the table size.

e. Run “node execute.js” locally.

Command:

node execute.js
Enter fullscreen mode Exit fullscreen mode

Sample output:

core-dynamodb-replication ak$ node execute.js
[AWS dynamodb 200 0.379s 0 retries] describeTable({ TableName: 'demo-dynamodb-poc-1-dynamodb' })
[AWS dynamodb 400 0.06s 0 retries] createTable({ AttributeDefinitions:
[ { AttributeName: 'ingest_date', AttributeType: 'S' },
{ AttributeName: 'record_id', AttributeType: 'S' },
[length]: 2 ],
TableName: 'demo-dynamodb-poc-new-dynamodb',
KeySchema:
[ { AttributeName: 'ingest_date', KeyType: 'HASH' },
{ AttributeName: 'record_id', KeyType: 'RANGE' },
[length]: 2 ],
BillingMode: 'PAY_PER_REQUEST',
SSESpecification: { Enabled: true } })
[AWS dynamodb 200 0.065s 0 retries] describeTable({ TableName: 'demo-dynamodb-poc-new-dynamodb' })
Creating Destination Table .[AWS dynamodb 200 0.07s 0 retries] scan({ TableName: 'demo-dynamodb-poc-1-dynamodb', Limit: 25 })
[AWS dynamodb 200 0.08s 0 retries] batchWriteItem({ RequestItems:
{ 'demo-dynamodb-poc-new-dynamodb':
[ { PutRequest:
{ Item:
{ ingest_date: { S: '2019-10-14' },
record_id: { S: 'R_00020191014' },
track: { S: '702' } } } },
{ PutRequest:
{ Item:
{ ingest_date: { S: '2019-10-12' },
record_id: { S: 'R_00020191012' },
track: { S: '704' } } } },
[length]: 2 ] } })
Copied 2 items{ count: 2, status: 'SUCCESS' }
core-dynamodb-replication ak$
Enter fullscreen mode Exit fullscreen mode

f. Login to destination account and verify if the DynamoDB table has been created.

Top comments (1)

Collapse
 
misfit99 profile image
Aman Sabale

Unexpected key 'TableClassSummary' found in params, I am getting this error