Dynamo doesn't keep any 'metadata' about what has been previously deleted. Considering you can't create a new attribute to keep track of deleted status, the only two ways I can think for you to handle this are:
Option 1: create your own 'metadata' table
Create a separate table to keep track of everything you deleted. You'd have a main
table where you store your regular data, and a main_deleted
table, where you store only primary_keys
that have been deleted from the main
table.
Before inserting any item in the main
table, check for the primary_key
in the main_deleted
table. If it's there, do not proceed with the insert.
Option 2: use the range_key
If your items have a sort key, you could use it to flag items as deleted without creating a new attribute. Suppose you have this item where the range_key is a UNIX timestamp:
{
"primary_key": "example",
"timestamp": 1234567890,
"other": "stuff"
}
Instead of deleting the item primary_key=example
, remove all its attributes and set the timestamp
to a value that you'd never use for regular items, such as 0
. When inserting or updating items in the table, use a condition expression or query the database previously to check if the item was not deleted before (in other words, timestamp=0
).
I'm sure there will be plenty of other ways and maybe (or probably) those two above aren't the best ones. Use your creativity! ;)