Follow dba-ninja.com

Subscribe to RSS feed  Follow @jackvamvas - Twitter

*Use the Comments section for questions

dba-ninja.com Links

Dba_db2_button

Sqlserver_dba_button

How to create a DynamoDB Global table from an existing table

31 October,2023 by Rambler

Question : How can I create a DynamoDB Global table from an existing table using AWS CLI ?

 

Answer:    For this example , we'll use 2 regions - us-east-1 and us-west-2.   

The goal is to create a DynamoDB Global table   - 

 

1) Create a new DynamoDB table in one region - (us-east-1).

aws dynamodb create-table \
       --table-name Guitarist \
        --attribute-definitions  \
        AttributeName=Name,AttributeType=S \
        AttributeName=Style,AttributeType=S \
        --key-schema \
        AttributeName=Name,KeyType=HASH \
        AttributeName=Style,KeyType=RANGE \
        --billing-mode PAY_PER_REQUEST \
        --stream-specification StreamEnabled=true,StreamViewType=NEW_AND_OLD_IMAGES \
        --region us-east-1

2)  Create an the same table but in another region (us-west-2)

aws dynamodb update-table --table-name Guitarist --cli-input-json  \
'{
  "ReplicaUpdates":
  [
    {
      "Create": {
        "RegionName": "us-west-2"
      }
    }
  ]
}' \
--region=us-east-1

3) Check that the newly create replica in us-west-2  exists   

aws dynamodb describe-table --table-name Guitarist --region us-east-1

4) Add some data , and check if the replication is working between the the two replicas

aws dynamodb put-item 
    --table-name Guitarist \
    --item '{"Name": {"S":"Hendrix"},"Style": {"S":"Rock"}}' \
    --region us-east-1




--Give it a few seconds and the check the data 

aws dynamodb scan --table-name Guitarist --region us-west-2


5) As an added test - add some data to the alternative region  and then check to see if the data is replicated back to us-east-1 

aws dynamodb put-item 
    --table-name Guitarist \
    --item '{"Name": {"S":"Metheny"},"Style": {"S":"Jazz"}}' \
    --region us-west-2




--Give it a few seconds and the check the data 

aws dynamodb scan --table-name Guitarist --region us-east-1

 

See Also 

How do I backup my DynamoDB table to another region with AWS Backup?

Amazon DynamoDB Backup & Restore

What is DynamoDB and how it works?

 


Author: Rambler (http://www.dba-ninja.com)


Share:

Verify your Comment

Previewing your Comment

This is only a preview. Your comment has not yet been posted.

Working...
Your comment could not be posted. Error type:
Your comment has been posted. Post another comment

The letters and numbers you entered did not match the image. Please try again.

As a final step before posting your comment, enter the letters and numbers you see in the image below. This prevents automated programs from posting comments.

Having trouble reading this image? View an alternate.

Working...

Post a comment on How to create a DynamoDB Global table from an existing table


dba-ninja.com