ステップ 6: グローバルセカンダリインデックスを作成します
このステップでは、「Music
」で作成した ステップ 1: テーブルを作成します テーブルのグローバルセカンダリインデックスを作成します。
グローバルセカンダリインデックスの詳細については、「DynamoDB のグローバルセカンダリインデックスの使用」を参照してください。
Amazon DynamoDB コンソールを使用して、Music
テーブルのグローバルセカンダリインデックス AlbumTitle-index
を作成するには:
DynamoDB コンソールを (https://console.aws.amazon.com/dynamodb/
) で開きます。 -
コンソールの左側のナビゲーションペインで、[Tables] (テーブル) を選択します。
-
テーブルのリストから [Music] テーブルを選択します。
-
[Music] テーブルの [インデックス] タブを選択します。
-
[インデックスの作成] を選択します。
-
[パーティションキー] に「
AlbumTitle
」と入力します。 -
[インデックス名] に「
AlbumTitle-index
」と入力します。 -
他の設定はデフォルト値のままにし、[インデックスを作成] を選択します。
次の AWS CLI の例では、AlbumTitle-index
を使用して Music
テーブルのグローバルセカンダリインデックス update-table
を作成します。
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:522194210714: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:522194210714:table/Music/index/AlbumTitle-index", "ItemCount": 0 } ], "ProvisionedThroughput": { "NumberOfDecreasesToday": 0, "WriteCapacityUnits": 5, "ReadCapacityUnits": 10 }, "TableSizeBytes": 0, "TableName": "Music", "TableStatus": "UPDATING", "TableId": "d04c7240-0e46-435d-b231-d54091fe1017", "KeySchema": [ { "KeyType": "HASH", "AttributeName": "Artist" }, { "KeyType": "RANGE", "AttributeName": "SongTitle" } ], "ItemCount": 0, "CreationDateTime": 1558028402.69 } }
IndexStatus
フィールドの値は CREATING
に設定されていることに注意してください。
DynamoDB がグローバルセカンダリインデックス AlbumTitle-index
の作成を終了したことを確認するには、describe-table
コマンドを使用します。
aws dynamodb describe-table --table-name Music | grep IndexStatus
このコマンドは、次の結果を返します。返された IndexStatus
フィールドの値が ACTIVE
に設定されている場合、インデックスは使用できる状態です。
"IndexStatus": "ACTIVE",
次に、グローバルセカンダリインデックスにクエリできます。詳細については、「ステップ 7: グローバルセカンダリインデックスをクエリします」を参照してください。