8
votes

Can we update a dynamodb item only with global secondary index?

$response = $dynamodbClient->updateItem(array(
            'TableName' => 'feed',
            'Key' => array(
                'feed_guid'      => array('S' => 'ac1e9683832ad2923f0bd84b91f34381'),
                'created_date'   => array('N' => '1439295833'),
            ),
            "ExpressionAttributeValues" =>  array (
                    ":val1" => array('N' => '1')
                ) ,
            "UpdateExpression" => $updateExpression,  
            'ReturnValues' => 'ALL_NEW'
        ));

In the above code, I want to replace the key section and update the item using a global secondary index, that is user_id.

2

2 Answers

10
votes

No, you cannot update items in a GSI. You make changes/updates to items in the table and those updates are propagated to the GSIs.

0
votes

A workaround I used for this was to first execute a query command using the document client, then extract the partition key from the result, and call the update method with my retrieved value as the key.