6단계: 글로벌 보조 인덱스 생성 - Amazon DynamoDB

6단계: 글로벌 보조 인덱스 생성

이 단계에서는 Music에서 생성한 1단계: 테이블 생성 테이블의 글로벌 보조 인덱스를 생성합니다.

글로벌 보조 인덱스에 관한 자세한 내용은 DynamoDB에서 글로벌 보조 인덱스 사용 단원을 참조하세요.

Amazon DynamoDB 콘솔을 사용하여 Music 테이블의 글로벌 보조 인덱스 AlbumTitle-index를 생성하려면

  1. https://console.aws.amazon.com/dynamodb/에서 DynamoDB 콘솔을 엽니다.

  2. 왼쪽 탐색 창에서 테이블을 선택합니다.

  3. 테이블 목록에서 [Music] 테이블을 선택합니다.

  4. Music 테이블의 [Indexes] 탭을 선택합니다.

  5. [Create index]를 선택합니다.

  6. 글로벌 보조 인덱스 생성 페이지에서 다음을 수행합니다.

    1. 파티션 키AlbumTitle을 입력합니다.

    2. (선택 사항) 인덱스 이름AlbumTitle-index를 입력합니다.

    3. 페이지의 다른 설정에 대해 기본 선택을 유지하고 인덱스 생성을 선택합니다.

      참고

      인덱스를 생성하면 인덱스가 새로 고쳐져 ACTIVE로 표시될 때까지 약간 기다려야 합니다.

다음 AWS CLI 예제에서는 update-table를 사용하여 Music 테이블의 글로벌 보조 인덱스 AlbumTitle-index를 생성합니다.

Linux

aws dynamodb update-table \ --table-name Music \ --attribute-definitions AttributeName=AlbumTitle,AttributeType=S \ --global-secondary-index-updates \ "[{\"Create\":{\"IndexName\": \"AlbumTitle-index\",\"KeySchema\":[{\"AttributeName\":\"AlbumTitle\",\"KeyType\":\"HASH\"}], \ \"ProvisionedThroughput\": {\"ReadCapacityUnits\": 10, \"WriteCapacityUnits\": 5 },\"Projection\":{\"ProjectionType\":\"ALL\"}}}]"

Windows CMD

aws dynamodb update-table ^ --table-name Music ^ --attribute-definitions AttributeName=AlbumTitle,AttributeType=S ^ --global-secondary-index-updates "[{\"Create\":{\"IndexName\": \"AlbumTitle-index\",\"KeySchema\":[{\"AttributeName\":\"AlbumTitle\",\"KeyType\":\"HASH\"}], \"ProvisionedThroughput\": {\"ReadCapacityUnits\": 10, \"WriteCapacityUnits\": 5},\"Projection\":{\"ProjectionType\":\"ALL\"}}}]"

update-table를 사용하면 다음 샘플 결과가 반환됩니다.

{ "TableDescription": { "TableArn": "arn:aws:dynamodb:us-west-2:111122223333:table/Music", "AttributeDefinitions": [ { "AttributeName": "AlbumTitle", "AttributeType": "S" }, { "AttributeName": "Artist", "AttributeType": "S" }, { "AttributeName": "SongTitle", "AttributeType": "S" } ], "GlobalSecondaryIndexes": [ { "IndexSizeBytes": 0, "IndexName": "AlbumTitle-index", "Projection": { "ProjectionType": "ALL" }, "ProvisionedThroughput": { "NumberOfDecreasesToday": 0, "WriteCapacityUnits": 5, "ReadCapacityUnits": 10 }, "IndexStatus": "CREATING", "Backfilling": false, "KeySchema": [ { "KeyType": "HASH", "AttributeName": "AlbumTitle" } ], "IndexArn": "arn:aws:dynamodb:us-west-2:111122223333:table/Music/index/AlbumTitle-index", "ItemCount": 0 } ], "ProvisionedThroughput": { "NumberOfDecreasesToday": 0, "WriteCapacityUnits": 5, "ReadCapacityUnits": 10 }, "TableSizeBytes": 0, "TableName": "Music", "TableStatus": "UPDATING", "TableId": "a04b7240-0a46-435b-a231-b54091ab1017", "KeySchema": [ { "KeyType": "HASH", "AttributeName": "Artist" }, { "KeyType": "RANGE", "AttributeName": "SongTitle" } ], "ItemCount": 0, "CreationDateTime": 1558028402.69 } }

IndexStatus 필드 값은 CREATING로 설정됩니다.

DynamoDB에서 AlbumTitle-index 글로벌 보조 인덱스 생성이 완료되었는지 확인하려면 describe-table 명령을 사용합니다.

Linux

aws dynamodb describe-table --table-name Music | grep IndexStatus

Windows CMD

aws dynamodb describe-table --table-name Music | findstr IndexStatus

이 명령은 다음 결과를 반환합니다. 반환되는 IndexStatus 필드 값이 ACTIVE로 설정되면 인덱스를 사용할 수 있습니다.

"IndexStatus": "ACTIVE",

그 다음에 글로벌 보조 인덱스를 쿼리할 수 있습니다. 세부 정보는 7단계: 글로벌 보조 인덱스 쿼리을 참조하세요.

중요

6단계를 완료한 후 잠시 기다려 주세요. 다음 단계에서는 6단계의 모든 작업을 완료하고 GSI 테이블을 ACTIVE해야 합니다.