I’ve inherited a service where the TTL value for the DynamoDB records is in the following format
2022-11-03T10:35:42.920Z
Does anyone know how I can run a query to delete all the records with a TTL value that is in the above format rather than Unix epoch time format?
2
Answers
The only way to retrieve and delete all items with a wrongly formatted TTL field is to perform a table scan, because there is no way to query for only those items. You can then either programmatically process all items in a programming language of your choice or use a filter expression that utilizes the
begins_with
function, to reduce the amount of data returned. Keep in mind that this will not reduce the necessary read capacity, only the bytes sent over the network. If you only have a few years in your TTL column, you can run multiple queries and adjust the corresponding year in thebegins_with
function.The following query would give you all items with a ISO formatted TTL field for 2022:
If you want to find out which items are requiring deletion you can return items which have
TTL
set as a String:Now, you must update those values for each item returned. If its a small dataset then you can easily iterate using the CLI and update each item. This would look something like this:
There is also alternatives for larger data sets, such as Step Functions Distributed Map.