Trabalhar com tabelas globais do DynamoDB e a replicação mutirregional usando a AWS Command Line Interface v2 - Amazon DynamoDB

Trabalhar com tabelas globais do DynamoDB e a replicação mutirregional usando a AWS Command Line Interface v2

O exemplo de código a seguir mostra como gerenciar tabelas globais do DynamoDB com replicação multirregional.

  • Crie uma tabela com replicação mutirregional.

  • Insira e obtenha itens de tabelas-réplica.

  • Remova as réplicas.

Bash
AWS CLI com script Bash

Crie uma tabela com replicação mutirregional.

# Step 1: Create a new table in us-west-2 aws dynamodb create-table \ --table-name MusicTable \ --attribute-definitions \ AttributeName=Artist,AttributeType=S \ AttributeName=SongTitle,AttributeType=S \ --key-schema \ AttributeName=Artist,KeyType=HASH \ AttributeName=SongTitle,KeyType=RANGE \ --billing-mode PAY_PER_REQUEST \ --region us-west-2 # Step 2: Create replicas in us-east-1 and us-east-2 aws dynamodb update-table \ --table-name MusicTable \ --replica-updates '[{"Create": {"RegionName": "us-east-1"}}, {"Create": {"RegionName": "us-east-2"}}]' \ --multi-region-consistency STRONG \ --region us-west-2

Descreva a tabela multirregional.

# Describe the base table aws dynamodb describe-table --table-name MusicTable --region us-west-2

Insira itens em uma tabela-réplica.

# Write a single item to one of the replica tables. aws dynamodb put-item \ --table-name MusicTable \ --item '{"Artist": {"S":"item_1"},"SongTitle": {"S":"Song Value 1"}}' \ --region us-east-2

Obtenha itens de tabelas-réplica.

# Get item from the other two replicas aws dynamodb get-item \ --table-name MusicTable \ --key '{"Artist": {"S":"item_1"},"SongTitle": {"S":"Song Value 1"}}' \ --consistent-read \ --region us-east-1 aws dynamodb get-item \ --table-name MusicTable \ --key '{"Artist": {"S":"item_1"},"SongTitle": {"S":"Song Value 1"}}' \ --consistent-read \ --region us-west-2

Remova as réplicas.

# Remove the replica tables. aws dynamodb update-table \ --table-name MusicTable \ --replica-updates '[{"Delete": {"RegionName": "us-east-2"}}, {"Delete": {"RegionName": "us-east-1"}}]' \ --region us-west-2

Para ver uma lista completa dos Guias do desenvolvedor e exemplos de código do SDK da AWS, consulte Usar o DynamoDB com um AWS SDK. Este tópico também inclui informações sobre como começar e detalhes sobre versões anteriores do SDK.