全局二级索引到现有表

时间:2018-01-31 13:06:11

标签: indexing amazon-dynamodb

我创建了DynamoDB table:

[
    'AttributeDefinitions' => [
        [
            'AttributeName' => 'UserId',
            'AttributeType' => 'N',
        ],
        [
            'AttributeName' => 'Created',
            'AttributeType' => 'S',
        ],
    ],
    'KeySchema' => [
        [
            'AttributeName' => 'UserId',
            'KeyType' => 'HASH',
        ],
        [
            'AttributeName' => 'Created',
            'KeyType' => 'RANGE',
        ],
    ],
    'ProvisionedThroughput' => [
        'ReadCapacityUnits' => 5,
        'WriteCapacityUnits' => 5,
    ],
    'TableName' => 'Images',
]

添加数据时,也会添加TargetUserIdUserId字段。如何为三列(UserId,TragetUserId,Created)设置GSI?或者我可能需要修改表KeySchema

看起来我无法使用AWS控制台(只有两个密钥可用):

enter image description here

1 个答案:

答案 0 :(得分:1)

DynamoDB密钥可以由一个属性(分区密钥)或两个属性(分区密钥和范围密钥)组成。

你应该创建一个新的属性,它结合了UserId + TargetUserIdUserId并使其成为GSI分区键,然后创建了创建范围键。

相关问题