Menu
Amazon DynamoDB
Developer Guide (API Version 2012-08-10)

Creating a Global Table

This section describes how to create a global table using the DynamoDB console, the AWS Command Line Interface (CLI), or the DynamoDB API.

Creating a Global Table (Console)

Follow these steps to create a global table using the console. The following example creates a global table with replica tables in United States and Europe.

  1. Open the DynamoDB console at https://console.aws.amazon.com/dynamodb/home. For this example, choose the us-east-2 (US East Ohio) region.

  2. In the navigation pane on the left side of the console, choose Tables.

  3. Choose Create Table.

    For Table name, type Music.

    For Primary key type Artist. Choose Add sort key, and type SongTitle. (Artist and SongTitle should both be strings.)

    To create the table, choose Create. This table will serve as the first replica table in a new global table, and will be the prototype for other replica tables that you add later.

  4. Choose the Global Tables tab, and then choose Enable streams. Leave the View type at its default value (New and old images).

  5. Choose Add region, and then choose another region where you want to deploy another replica table. In this case, choose US West (Oregon), and then choose Continue. This will start the table creation process in US West (Oregon).

    The console will check to ensure that there is no table with the same name in the selected region. (If a table with the same name does exist, then you must delete the existing table before you can create a new replica table in that region.)

    The Global Table tab for the selected table (and for any other replica tables) will show that the table is replicated in multiple regions.

  6. You will now add another region, so that your global table is replicated and synchronized across the United States and Europe. To do this, repeat Step 5, but this time specify EU (Frankfurt) instead of US West (Oregon).

  7. You should still be using the AWS Management console in the us-east-2 (US East Ohio) region. For the Music table, choose the Items tab, and then choose Create Item. For Artist, type item_1. For SongTitle, type Song Value 1. To write the item, choose Save.

    After a short time, the item is replicated across all three regions of your global table. To verify this, in the AWS Management Console, go to the region selector in the upper right-hand corner and choose EU (Frankfurt). The Music table in EU (Frankfurt) should contain the new item.

    Repeat this for US West (Oregon).

Creating a Global Table (AWS CLI)

Follow these steps to create a global table Music using the AWS CLI. The following example creates a global table, with replica tables in the United States and in Europe.

  1. Create a new table (Music) in US East (Ohio), with DynamoDB Streams enabled (NEW_AND_OLD_IMAGES):

    aws dynamodb create-table \ --table-name Music \ --attribute-definitions \ AttributeName=Artist,AttributeType=S \ AttributeName=SongTitle,AttributeType=S \ --key-schema \ AttributeName=Artist,KeyType=HASH \ AttributeName=SongTitle,KeyType=RANGE \ --provisioned-throughput \ ReadCapacityUnits=10,WriteCapacityUnits=5 \ --stream-specification StreamEnabled=true,StreamViewType=NEW_AND_OLD_IMAGES \ --region us-east-2
  2. Create an identical Music table in US East (N. Virginia):

    aws dynamodb create-table \ --table-name Music \ --attribute-definitions \ AttributeName=Artist,AttributeType=S \ AttributeName=SongTitle,AttributeType=S \ --key-schema \ AttributeName=Artist,KeyType=HASH \ AttributeName=SongTitle,KeyType=RANGE \ --provisioned-throughput \ ReadCapacityUnits=10,WriteCapacityUnits=5 \ --stream-specification StreamEnabled=true,StreamViewType=NEW_AND_OLD_IMAGES \ --region us-east-1
  3. Create a global table (Music) consisting of replica tables in the us-east-2 and us-east-1 regions.

    aws dynamodb create-global-table \ --global-table-name Music \ --replication-group RegionName=us-east-2 RegionName=us-east-1 \ --region us-east-2

    Note

    The global table name (Music) must match the name of each of the replica tables (Music). For more information, see Requirements and Best Practices.

  4. Create another table in EU (Ireland), with the same settings as those you created in Step 1 and Step 2:

    aws dynamodb create-table \ --table-name Music \ --attribute-definitions \ AttributeName=Artist,AttributeType=S \ AttributeName=SongTitle,AttributeType=S \ --key-schema \ AttributeName=Artist,KeyType=HASH \ AttributeName=SongTitle,KeyType=RANGE \ --provisioned-throughput \ ReadCapacityUnits=10,WriteCapacityUnits=5 \ --stream-specification StreamEnabled=true,StreamViewType=NEW_AND_OLD_IMAGES \ --region eu-west-1

    After you have done this, add this new table to the Music global table:

    aws dynamodb update-global-table \ --global-table-name Music \ --replica-updates 'Create={RegionName=eu-west-1}' \ --region us-east-2
  5. To verify that replication is working, add a new item to the Music table in US East (Ohio):

    aws dynamodb put-item \ --table-name Music \ --item '{"Artist": {"S":"item_1"},"SongTitle": {"S":"Song Value 1"}}' \ --region us-east-2
  6. Wait for a few seconds, and then check to see if the item has been successfully replicated to US East (N. Virginia) and EU (Ireland):

    aws dynamodb get-item \ --table-name Music \ --key '{"Artist": {"S":"item_1"},"SongTitle": {"S":"Song Value 1"}}' \ --region us-east-1
    aws dynamodb get-item \ --table-name Music \ --key '{"Artist": {"S":"item_1"},"SongTitle": {"S":"Song Value 1"}}' \ --region eu-west-1