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.
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. Save this answer.
A global secondary index contains a selection of attributes from the base table, but they are organized by a primary key that is different from that of the table. The index key does not need to have any of the key attributes from the table. It doesn't even need to have the same key schema as a table.
AWS DynamoDB CLIYou can create a Global Secondary Index at the same time you create a DDB table using create-table command. You can also use AWS DynamoDB update-table command to create a Global Secondary Index after creating a DDB table.
A secondary index is a data structure that contains a subset of attributes from a table, along with an alternate key to support Query operations. You can retrieve data from the index using a Query , in much the same way as you use Query with a table.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With