Reputation: 6854
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?
Upvotes: 11
Views: 37958
Reputation: 3075
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 usePutItem
to create a new item with new attributes.
Upvotes: 9
Reputation: 134
In DynamoDB, you can perform a conditional update on an existing item(insert a new attribute name-value pair if it doesn't exist, or replace an existing name-value pair if it has certain expected attribute values). Refer to the official documentation here: https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_UpdateItem.html
Also, you may consider using sort keys the right way. Please refer to the suggested documentation here: https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/bp-sort-keys.html
Upvotes: -2
Reputation: 1530
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
Upvotes: 33