Home > Net >  Last writer wins uniqueness in DynamoDB secondary indexes
Last writer wins uniqueness in DynamoDB secondary indexes

Time:11-17

Can I overwrite an entry in a DynamoDB index be it global or local?

I do not want duplicate entries, but want DynamoDB to overwrite if an entry with same pk sk exist in the index.

CodePudding user response:

That's not how it works. Local and Global Secondary Indexes explicitly make no guarantees about uniqueness.

From the docs for Local Secondary Indexes:

In a DynamoDB table, the combined partition key value and sort key value for each item must be unique. However, in a local secondary index, the sort key value does not need to be unique for a given partition key value.

docs

From the docs for Global Secondary Indexes:

In a DynamoDB table, each key value must be unique. However, the key values in a global secondary index do not need to be unique.

docs

Only the base table enforces uniqueness for the primary key - it's nothing that can be enforced by the system for LSIs or GSIs. If you need uniqueness there, you have to design your app and data model to ensure collisions can't happen.

CodePudding user response:

Given that you don't (and can't) write to a GSI/LSI explicitly...

You'll need to ensure that you're updating the appropriate table record whose attributes used for LSI/GSI are changing..

In other words, for there to be only a single record in the GSI/LSI there can be only a single record in the with attribute values used in the GSI/LSI

  • Related