2

I have table with "RefNumber", "status" and "Date". "RefNumber" is the partition Key and "Status" is the sort key So, both make a primary key.

{
    "RefNumber": "122345",
    "Status": "0",
    "DateTime": 15343354545
}

Now after fetching this record, I want to update "Status" with "1". I have multiple workers reading the DynamoDB records, just to avoid any 2 workers processing the same record I want to fetch and update the "Status" with "1" using ConditionExpression, if the update succeeds the worker will process else it will skip.

My question is, is it a good design to update the attribute value which is part of the primary key in dynamodb

Dhananjay
  • 85
  • 1
  • 11

1 Answers1

3

The short answer is No, it is not possible to update an attribute that forms the Key of an item in DynamoDB.

You can only delete the item and create another one.

If you consider this, logically, modifying a key of an element doesn’t make any sense: an element is uniquely identified by it’s key, so what does it even mean that you’re mutating the key? It would mean the old element is replaced entirely.

DynamoDB does not offer an atomic “replace” operation.

Mike Dinescu
  • 54,171
  • 16
  • 118
  • 151