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.
When Putting an item into a table that already exists in the table, DynamoDB will "overwrite" (delete the existing record and write the new one) so as to avoid duplicates
DynamoDB will overwrite a record if the incoming record's primary key matches that of an existing one in the table. For example, { primaryKey: "hey", otherAttribute: "yo" }
will overwrite { primaryKey: "hey", otherAttribute: "sup" }
because their primary keys match
There are no uniqueness
If I have an API that gets a record from a table, modifies the records attributes including changing its primary key value to something new and unique, and subsequently Puts it back into the table, it would be considered a new unique record and not overwrite the original retrieved record. It would essentially be a new record that matches an existing record except for the modified attributes and primary key.
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.
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.