Search code examples
amazon-web-servicesamazon-dynamodbdynamodb-queriesamazon-dynamodb-index

Can we update a fetch a record and update the Primary key attribute in DynamoDB?


Let's say we have a DynamoDB record with Primary Key: A1 and GSI (Hash Key: B1 and RangeKey: C1).

And we have the following records in the database:

A1        B1        C1
--------------------------
value1    value2    value3
value4    value5    value6

Now, I want to query a record with Primary Key A1 with value value1 and update the same A1 attribute to value7.

If we can do this, what is the impact on other partitions. Will we run into any issues if we do it like this?

Does this have any impact on the table? Given we operate at a large scale.


Solution

  • You cannot do this.

    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.

    From: Amazon DynamoDB API Reference AttributeValueUpdate

    By creating new item, obviously there will be no tragic implications.