Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DynamodDB: How to update sort key?

The table has two keys: filename (partition key) and eventTime (sort key). I want to update eventTime for certain filename. Tried put_item() and update_item() sending the same filename with new eventTime but those functions add a new item instead of update.

What should I use for that purpose?

like image 909
Putnik Avatar asked Apr 02 '19 12:04

Putnik


2 Answers

You can't. Since it is part of the index, the field is protected. What you should do it to delete the item and add it again with the new sort key.

See https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_AttributeValueUpdate.html

like image 128
Stargazer Avatar answered Sep 23 '22 13:09

Stargazer


According to DynamoDB/AttributeValueUpdate aws docs:

You cannot use UpdateItem to update any primary key attributes. Instead, you will need to delete the item, and then use PutItem to create a new item with new attributes.

like image 25
GorkemHalulu Avatar answered Sep 25 '22 13:09

GorkemHalulu