This exercise will show you the steps for using the Global Tables engine for Amazon DynamoDB tables. If you want more information click here.
By the end of this exercise, you will be able to:
Estimated Duration: 15 minutes
Approximate Cost: 1 USD
aws dynamodb create-table \
--table-name Music \
--attribute-definitions \
AttributeName=Artist,AttributeType=S \
AttributeName=Song,AttributeType=S \
--key-schema \
AttributeName=Artist,KeyType=HASH \
AttributeName=Song,KeyType=RANGE \
--billing-mode PAY_PER_REQUEST \
--stream-specification StreamEnabled=true,StreamViewType=NEW_AND_OLD_IMAGES \
--region us-east-1
Create a table Music identical in US West (N. California).
aws dynamodb update-table --table-name Music --cli-input-json --region us-east-1 \
'{
"ReplicaUpdates":
[
{
"Create": {
"RegionName": "us-west-1"
}
}
]
}'
(Optional) You can view the list of replicas created using describe-table.
aws dynamodb describe-table --table-name Music --region us-east-1
If any of the tables are not in the list of replicates, wait a few minutes for them to be created.
To verify that replication is working, add a new item to the Music table in the region US East (N. Virginia).
aws dynamodb put-item \
--table-name Music \
--item '{"Artist": {"S":"The Beatles"},"Song": {"S":"Hey Jude"}}' \
--region us-east-1
To verify that replication is bidirectional, add a new item to the Music table in the region US East (N. California).
aws dynamodb put-item \
--table-name Music \
--item '{"Artist": {"S":"The Clash"},"Song": {"S":"London Calling"}}' \
--region us-west-1
Make sure the items have been successfully replicated to the regions:
aws dynamodb scan --table-name Music --region us-east-1
aws dynamodb scan --table-name Music --region us-west-1
Delete the replica table in the region US West (N. California).
aws dynamodb update-table --table-name Music --cli-input-json --region us-east-1 \
'{
"ReplicaUpdates":
[
{
"Delete": {
"RegionName": "us-west-1"
}
}
]
}'
Wait a few minutes until the secondary table be deleted. The primary table status will change from UPDATING to ACTIVE. You can check the deletion already finished using the command below:
aws dynamodb describe-table --table-name Music --region us-east-1 | jq -r '.Table.TableStatus'
After the deletion of secondary table be completed, delete the primary table Music in the region US East (N. Virginia).
aws dynamodb delete-table --table-name Music --region us-east-1
With this exercise, it was possible to verify how replicated Amazon DynamoDB tables can be used in a strategy of the type. Active-Active, both for reading and for data persist.