AWS Certified SysOps Administrator - Associate
Domain 2 Reliability and BCP
Demo Setting up Global Tables with DynamoDB
Welcome to this detailed lesson on setting up global tables using DynamoDB. In this guide, you will learn how to automate the creation of a DynamoDB table with CloudFormation and configure it for global replication to support robust, geographically distributed applications.
CloudFormation Template for DynamoDB Table
The following CloudFormation template creates a basic DynamoDB table named "CustomerData." The table uses on-demand pricing (PAY_PER_REQUEST) and defines two attributes: CustomerId (partition key) and OrderDate (sort key). Additionally, it is configured with a stream that captures both new and old images—a prerequisite for enabling global tables.
AWSTemplateFormatVersion: '2010-09-09'
Resources:
CustomerDataTable:
Type: AWS::DynamoDB::Table
Properties:
TableName: CustomerData
BillingMode: PAY_PER_REQUEST
AttributeDefinitions:
- AttributeName: CustomerId
AttributeType: S
- AttributeName: OrderDate
AttributeType: S
KeySchema:
- AttributeName: CustomerId
KeyType: HASH
- AttributeName: OrderDate
KeyType: RANGE
StreamSpecification:
StreamViewType: NEW_AND_OLD_IMAGES
Outputs:
TableName:
Description: Name of the DynamoDB table
Value: !Ref CustomerDataTable
TableArn:
Description: ARN of the DynamoDB table
Value: !GetAtt CustomerDataTable.Arn
The CloudFormation template above automates the deployment of a DynamoDB table that meets the prerequisites for global replication. Once the table is created in the US West 2 (Oregon) region, you can then proceed with the replication setup.
Verifying DynamoDB Table Settings
After deploying the table, log in to the DynamoDB console to verify its configuration. Navigate to the table details and check the "Exports and streams" tab to ensure that the DynamoDB stream is enabled and configured to capture both new and old images. The following images illustrate the settings you should see:
Creating Global Table Replicas
Once your table is properly configured and verified, switch to the Global Tables tab in the console.
Historically, setting up DynamoDB Global Tables required creating separate tables and manually configuring replicas. With the latest update, you can simply select your existing table and create a replica in another region.
Currently, the table is set up in the US West 2 region. You have the option to choose between eventual consistency, which offers lower write latencies, or global strong consistency for reads (which might introduce some delay due to additional replication overhead). In this example, you will create a replica in US East 1 (North Virginia) using eventual consistency.
Note
Strong consistency for global tables is still in preview and is not generally available.
During the replica creation, the console displays a status—initially showing that the table is updating. Once replication is complete, the status will change to "active," and the replica region count will update accordingly.
After completing the replica setup, switch to the North Virginia region to verify that the table has been successfully replicated. The Global Tables tab should display the new replica alongside the original table.
Testing Global Replication
Once the global table is fully configured, test the replication by inserting sample items into the table. For instance, insert an item with a CustomerId such as "customer 123" and an OrderDate like "2023-01-15." Then, add additional items—e.g., with CustomerIds "customer four, five, and six" and an OrderDate set to "2025-04-09."
These entries will help you confirm that changes in one region are automatically replicated to the other. When you inspect the table in both Oregon and North Virginia, the presence of identical records verifies successful replication.
Monitoring Replication Latency
Keeping an eye on replication performance is crucial. Navigate to the Monitor section of your DynamoDB table to view key metrics such as query latency, scan latency, and replication latency. Replication latency (sometimes called replication lag) measures the delay—often in milliseconds—in propagating changes across regions. In this demonstration, you might observe a latency of approximately 300 milliseconds.
Key Takeaways
- Global Tables can be easily configured by creating a DynamoDB table with a stream enabled for new and old images.
- Maintaining a consistent table name and key schema across regions is essential.
- CloudFormation automates the creation and configuration of DynamoDB tables, simplifying deployment.
- Global replication is achieved by creating replicas in additional regions directly from the Global Tables tab.
- Monitoring replication latency ensures your application meets cross-region consistency requirements.
This comprehensive demonstration shows how to set up and verify DynamoDB global tables, ultimately enabling you to build robust, globally distributed applications with ease.
Watch Video
Watch video content
Practice Lab
Practice lab