amazon-web-servicesamazon-dynamodbunique-constraint

Why does Getting a record, modifying its primary key, and then Putting it back seem to overwrite the record if the primary keys are different?


I have some confusion regarding the behavior of DynamoDB when writing a record.

Before describing my question, I should establish my understanding of how it all works. Please indicate if I'm misunderstanding something.

As for my situation:

I have a Lambda being hit daily on a cronjob that gets a record from a table, modifies its primary key along with some other attributes, and Puts it back into the same table. However, while I am able to verify in the actual table that the new record has been inserted, I am unable to find the original record that was retrieved by the cronjob.

It appears instead that the record was pulled from the table, was modified by my Lambda, and then was Put back into the same table overwriting the original record.

But as far as I can tell that shouldn't happen, because their primary keys differ and for all intents and purposes are non-matching, according to DynamoDB.

Why does retrieving a record, modifying its primary key, and re-inserting it to the table overwrite the record if the primary key is different? Is there something that's informing DynamoDB that this incoming record is "the same" as the one that was retrieved, despite having different primary keys?

I will provide clarification on my situation if requested.


Solution

  • I've found an explanation for the behavior.

    DynamoDB's behavior is consistent, as expected.

    The records were indeed being submitted as duplicates, but the originals were not showing up in my date-indexed queries due to the date formats not being valid (which is one of the things needing fixed that led to this question in the first place).

    Mystery solved - reminding my future self to ensure data is cleaned before processing it.