AWS Command Line Interface v2 を使用して DynamoDB グローバルテーブルとマルチリージョンレプリケーションを操作する - AWS SDK コードの例

Doc AWS SDK Examples GitHub リポジトリには、他にも SDK の例があります。 AWS

翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。

AWS Command Line Interface v2 を使用して DynamoDB グローバルテーブルとマルチリージョンレプリケーションを操作する

次のコード例は、マルチリージョンレプリケーションを備えた DynamoDB グローバルテーブルを管理する方法を示しています。

  • マルチリージョンレプリケーションを備えたテーブルを作成します。

  • レプリカテーブルの項目を配置および取得します。

  • レプリカを削除します。

Bash
AWS CLI Bash スクリプトを使用する

マルチリージョンレプリケーションを備えたテーブルを作成します。

# 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

マルチリージョンテーブルについて説明します。

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

レプリカテーブルに項目を配置します。

# 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

レプリカテーブルから項目を取得します。

# 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

レプリカを削除します。

# 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