DEV Community

Arun Kumar for AWS Community Builders

Posted on

3 1

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.

Do your career a big favor. Join DEV. (The website you're on right now)

It takes one minute, it's free, and is worth it for your career.

Get started

Community matters

Top comments (1)

Collapse
 
misfit99 profile image
Aman Sabale

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

Create a simple OTP system with AWS Serverless cover image

Create a simple OTP system with AWS Serverless

Implement a One Time Password (OTP) system with AWS Serverless services including Lambda, API Gateway, DynamoDB, Simple Email Service (SES), and Amplify Web Hosting using VueJS for the frontend.

Read full post

👋 Kindness is contagious

Dive into an ocean of knowledge with this thought-provoking post, revered deeply within the supportive DEV Community. Developers of all levels are welcome to join and enhance our collective intelligence.

Saying a simple "thank you" can brighten someone's day. Share your gratitude in the comments below!

On DEV, sharing ideas eases our path and fortifies our community connections. Found this helpful? Sending a quick thanks to the author can be profoundly valued.

Okay