Can I Set Up Automatic Deletion for Items in DynamoDB Based on Status?

0
2
Asked By CuriousCoder92 On

I'm trying to figure out if there's a way to automatically delete items in DynamoDB if they stay at a certain value for too long. For instance, if I have an item with a 'status' key, I'd like it to be deleted if its value is 'processing' for more than an hour. I know about the Time to Live (TTL) feature, but my TTL setup is around 8 hours for logging and caching. Is there a way to implement this conditional deletion based on time?

3 Answers

Answered By LambdaLover77 On

You could achieve this easily by using a Lambda function along with an EventBridge rule. Basically, you set up the Lambda function to check the items periodically and delete them if they meet your criteria.

QuestionAsker -

That sounds great! Could you explain how to set that up?

Answered By DataGuru88 On

One approach is to utilize the TTL feature smartly. When the item is in 'processing', add a specific key that defines its state. Once the key is set, the TTL will handle the auto-deletion after the defined time. It might also be useful to have a cleanup job that routinely checks for 'processing' items that haven't been set with a TTL to remove or flag them accordingly.

Answered By CreativeThinker43 On

Instead of deleting the item, how about modifying the value to include a timestamp? For example, change 'processing' to 'processing-20250514003059'. This way, you can still filter by the status but ignore older records by querying those with a timestamp greater than a certain threshold.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.