AWS Command Line Interface v2를 사용한 DynamoDB 글로벌 테이블 및 다중 리전 복제 작업 - AWS SDK 코드 예제

Doc AWS SDK 예제 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