Giter Site home page Giter Site logo

miztiik / dynamodb-global-tables Goto Github PK

View Code? Open in Web Editor NEW
3.0 2.0 6.0 477 KB

Amazon DynamoDB global tables provide a fully managed solution for deploying a multi-region, multi-master database.

Home Page: https://www.udemy.com/course/aws-cloud-development-kit-from-beginner-to-professional/?referralCode=E15D7FB64E417C547579&couponCode=AWS_4U_MAY

valaxy dynamodb multi-master multi-region global-tables dynamodb-streams

dynamodb-global-tables's Introduction

AWS DynamoDB Global Tables: Multi Region, Multi Master Database

As a learning exercise, lets use the AWS Documentation and find out how to create Global Multi Master, Multi Region database with DynamoDB and verify latency.

A global table is a collection of one or more replica tables, all owned by a single AWS account. A replica table (or replica, for short) is a single DynamoDB table that functions as a part of a global table. Each replica stores the same set of data items. Any given global table can only have one replica table per region.

AWS DynamoDB Global Tables

Follow this article in Youtube

Setup The Tables

The following is a conceptual overview of how a global table is created.

  1. Create an ordinary DynamoDB table, with DynamoDB Streams enabled, in an AWS region.

    • Region 1 - Singapore
    • Region 2 - Virginia
    • Region 3 - Ireland
  2. Repeat step 1 for every other AWS region where you want to replicate your data.

  3. Define a DynamoDB global table, based upon the tables that you have created.

  4. Create a new table (Music) in Singapore, 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=1,WriteCapacityUnits=1 \
        --stream-specification StreamEnabled=true,StreamViewType=NEW_AND_OLD_IMAGES \
        --region ap-southeast-1
  5. 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=1,WriteCapacityUnits=1 \
        --stream-specification StreamEnabled=true,StreamViewType=NEW_AND_OLD_IMAGES \
        --region us-east-1
  6. Create a global table (Music) consisting of replica tables in the ap-southeast-1 and us-east-1 regions.

    aws dynamodb create-global-table \
        --global-table-name Music \
        --replication-group RegionName=ap-southeast-1 RegionName=us-east-1 \
        --region ap-southeast-1
  7. 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=1,WriteCapacityUnits=1 \
        --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 ap-southeast-1

Verify Global Replication

  1. To verify that replication is working, add a new item to the Music table in Singapore:

    aws dynamodb put-item \
        --table-name Music \
        --item '{"Artist": {"S":"item_1"},"SongTitle": {"S":"Song Value 1"}}' \
        --region ap-southeast-1
  2. 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

Timing Your Insert/Read Queries

Lets do some crude inserts and time their replication

for i in {2..10}
 do
  val=${RANDOM}
  t=2
  # Insert Items
  echo -e "\n\n-=-=- Inserting Item:item_${i} and Retrieving after ${t} Seconds -=-=-"
  aws dynamodb put-item --table-name Music --item '{"Artist": {"S":"item_'${i}'"},"SongTitle": {"S":"Song Value '${val}'"}}' --region ap-southeast-1
  sleep ${t}
  # Read Items
  time aws dynamodb get-item --table-name Music --key '{"Artist": {"S":"item_'${i}'"},"SongTitle": {"S":"Song Value '${val}'"}}' --region eu-west-1
 done

Contact Us

You can reach out to us to get more details through here.

References
  1. AWS Docs

dynamodb-global-tables's People

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.