Roman Newaza
Roman Newaza

Reputation: 11690

Global Secondary Index To an Existing Table

I have created 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',
]

Adding a data, TargetUserIdUserId field is added as well. How do I set GSI for three columns (UserId, TragetUserId, Created)? Or maybe I need to modify table KeySchema?

Looks like I cannot do it using AWS Console (only two keys are available):

enter image description here

Upvotes: 0

Views: 180

Answers (1)

F_SO_K
F_SO_K

Reputation: 14799

A DynamoDB key can be made of one attribute (partition key) or two attributes (partition key and range key).

You should create a new attribute which combines UserId + TargetUserIdUserId and make this the GSI partition key, then make Created the range key.

Upvotes: 1

Related Questions