Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Update an item using partition key of Global Secondary index

Hi every body i am working on dynamodb and very new to this technology i studied it with detail and i have been stuck in a problem since last week and could not found any help. i want to use the partition key of Global secondary index to update and delete item rather than using partition key of Base table. i could not get any way to update and delete items in dynamodb using partition key Global secondary index.

 DynamoDB dyn = new DynamoDB(dynamoDB);
Table table = dyn.getTable(tableName);
com.amazonaws.services.dynamodbv2.document.Index index = 
table.getIndex(indexName);
index.updateItemRequest(); // not supported
like image 505
Sajjad Haider Avatar asked Sep 03 '25 08:09

Sajjad Haider


1 Answers

You cannot delete an item using the key of the Global Secondary Index (GSI).

In order to delete an item you need the table's key (partition key + sorting key). One way to get this key is by querying the GSI.

So: GSI Key -> query on GSI -> Table Key -> Delete.

Update works the same way: GSI Keys -> query on GSI -> Table Key -> Update.

like image 84
Costin Avatar answered Sep 04 '25 23:09

Costin