Important Note: You will create AWS resources during the exercise which will incur cost in your AWS account. It is recommended to clean-up the resources as soon as you finish the exercise to minimize the cost.

Understanding Global Tables in DynamoDB

Amazon DynamoDB is a key-value and document database that delivers high performance at scale. Amazon DynamoDB global tables provide a managed solution for deploying a multiregion and multi-active database. One can specify the AWS Regions for the global tables and DynamoDB takes care of all the necessary tasks to replicate ongoing data changes to all of them.

In this exercise, you configure and use Global Tables in DynamoDB table.

Step1: Pre-Requisite


You need to have an AWS account with administrative access to complete the exercise. If you don’t have an AWS account, kindly use the link to create free trial account for AWS.

Step2: Create DynamoDB Table


You start with creation of a DynamoDB table dojotable.

  1. Login to AWS Management Console and select Ireland as the region.

  2. The exercise is using the new UI console for DynamoDB. Goto DynamoDB console. Select Tables menu in the left and then click on the Create table button.

    Amazon DynamoDB

  3. On the next screen, type in dojotable as the table name. Type in id as the partition key with data type selected as Number. Keep rest of the configuration to the default and click on the Create table button.

    Amazon DynamoDB

  4. The table is created in no time. You configure Global Tables for the DynamoDB table.

Step3: Configure Global Tables


You configure two global tables for the Singapore and Oregon regions.

  1. Open the details of the dojotable. Click on the Global tables tab and then click on the Create replica button.

    Amazon DynamoDB

  2. On the next screen, select Oregon as the replication region and click on the Create replica button.

    Amazon DynamoDB

  3. It will start creating the Global table in the Oregon region. Wait till the status of the replica changes to Active.

    Amazon DynamoDB

  4. Repeat steps 1 to 3 to create another replica in the Singapore region.

    Amazon DynamoDB

  5. The replicas are in place. Let’s work with the data and see global tables in action.

Step4: Data Replication in Global Table


You use PartiQL Editor to insert, update and delete data in the DynamoDB table and you will see it getting replicated across various regions due to global table configuration.

  1. In Ireland Region, in DynamoDB Management console, click on the PartiQL editor menu in the left. Copy-paste the following SQL Statements one by one and click on the Run button.

    INSERT INTO dojotable value {'id' : 1,'name' : 'John Smith', 'title' : 'Data Engineer'}
       
    INSERT INTO dojotable value {'id' : 2,'name' : 'Robert Deen', 'title' : 'Data Analyst'}
    

    `

    Amazon DynamoDB

  2. The data inserted in Ireland region should get replicated to Singapore and Oregon regions. Change the region to Oregon and run the following query in the PartiQL editor to see the replicated data. You can check the replication in the Singapore region in the same way.

    select * from dojotable
    

    `

    Amazon DynamoDB

  3. In Ireland Region, Run the following queries one by one in PartiQL editor to delete and update records in the DynamoDB table.

    DELETE FROM dojotable WHERE id = 1
       
    UPDATE dojotable SET title= 'Data Specialist' WHERE id= 2
    

    `

  4. The data updates in Ireland region should get replicated to Singapore and Oregon regions. Change the region to Singapore and run the following query in the PartiQL editor to see the updated data. You can check the data in the Oregon region in the same way.

    select * from dojotable
    

    `

    Amazon DynamoDB

  5. In Singapore Region, Run the following query to insert a record using PartiQL editor.

    INSERT INTO dojotable value {'id' : 3,'name' : 'Ivanka Den', 'title' : 'Data Scientist'}
    

    `

  6. The data updates in replica region like in this case Singapore also get updated to other regions.Change the region to Ireland and run the following query in the PartiQL editor to see the updated data. You can check the data in the Oregon region in the same way.

    select * from dojotable
    

    `

    Amazon DynamoDB

  7. This finishes the exercise. Follow the next step to clean-up resources so that you don’t incur any cost post the exercise.

Step5: Clean up


Delete dojotable DynamoDB table in the Ireland region.

Thanks and hope you enjoyed the exercise.


Back to the Exercises