AWS Command Line Interface v2를 사용하여 DynamoDB 글로벌 보조 인덱스 관리
다음 코드 예제에서는 글로벌 보조 인덱스의 전체 수명 주기를 관리하는 방법을 보여줍니다.
글로벌 보조 인덱스가 있는 테이블을 생성합니다.
기존 테이블에 새 GSI를 추가합니다.
GSI 웜 처리량을 업데이트(증가)합니다.
GSI를 사용하여 데이터를 쿼리합니다.
GSI를 삭제합니다.
- Bash
-
- Bash 스크립트와 함께 AWS CLI사용
-
글로벌 보조 인덱스가 있는 테이블을 생성합니다.
# Create a table with a GSI aws dynamodb create-table \ --table-name MusicCollection \ --attribute-definitions \ AttributeName=Artist,AttributeType=S \ AttributeName=SongTitle,AttributeType=S \ AttributeName=AlbumTitle,AttributeType=S \ --key-schema \ AttributeName=Artist,KeyType=HASH \ AttributeName=SongTitle,KeyType=RANGE \ --billing-mode PAY_PER_REQUEST \ --global-secondary-indexes \ "IndexName=AlbumIndex,\ KeySchema=[{AttributeName=AlbumTitle,KeyType=HASH}],\ Projection={ProjectionType=ALL}"
기존 테이블에 새 (온디맨드) GSI를 추가합니다.
# Add a new GSI to an existing table aws dynamodb update-table \ --table-name MusicCollection \ --attribute-definitions \ AttributeName=Genre,AttributeType=S \ --global-secondary-index-updates \ "[{\"Create\":{\"IndexName\":\"GenreIndex\",\ \"KeySchema\":[{\"AttributeName\":\"Genre\",\"KeyType\":\"HASH\"}],\ \"Projection\":{\"ProjectionType\":\"ALL\"}}}]"
GSI 웜 처리량을 업데이트(증가)합니다.
# Increase the warm throughput of a GSI (default values are 12k reads, 4k writes) aws dynamodb update-table \ --table-name MusicCollection \ --global-secondary-index-updates \ "[{\"Update\":{\"IndexName\":\"AlbumIndex\",\ \"WarmThroughput\":{\"ReadUnitsPerSecond\":15000,\"WriteUnitsPerSecond\":6000}}}]"
GSI를 사용하여 데이터를 쿼리합니다.
# Query the AlbumIndex GSI aws dynamodb query \ --table-name MusicCollection \ --index-name AlbumIndex \ --key-condition-expression "AlbumTitle = :album" \ --expression-attribute-values '{":album":{"S":"Let It Be"}}' # Query the GenreIndex GSI aws dynamodb query \ --table-name MusicCollection \ --index-name GenreIndex \ --key-condition-expression "Genre = :genre" \ --expression-attribute-values '{":genre":{"S":"Jazz"}}'
GSI를 삭제합니다.
# Delete a GSI from a table aws dynamodb update-table \ --table-name MusicCollection \ --global-secondary-index-updates \ "[{\"Delete\":{\"IndexName\":\"GenreIndex\"}}]"
-
API 세부 정보는 AWS CLI 명령 참조의 다음 토픽을 참조하세요.
-
AWS SDK 개발자 가이드 및 코드 예제의 전체 목록은 AWS SDK와 함께 DynamoDB 사용 섹션을 참조하세요. 이 주제에는 시작하기에 대한 정보와 이전 SDK 버전에 대한 세부 정보도 포함되어 있습니다.
브라우저에서 Lambda 함수 간접 호출
리소스 기반 정책 관리