DynamoDB tables can be truncated via AWS console, but I’d like to do this in a script.
All the answers I saw on S.O. regarding this topic involved ‘scans’ and similar stuff that I didn’t completely understand. I’m wondering if there is a simple directive that I can use to accomplish this truncation. Thanks !
Question posted in Amazon Web Sevices
The official Amazon Web Services documentation can be found here.
The official Amazon Web Services documentation can be found here.
3
Answers
Use dynamodbdump
It has a wipe-data option which is fast and simple and less hassle, you dont have to write any script or any manual effort rather just running this simple command .
example
https://github.com/mifi/dynamodump
You can’t. You need to delete the table. What all the scripts are doing is scanning the entire table and delete each item. Better to delete the table and create it with the same name
While it’s not straight forward, you can combine a couple commands to get you there w/o needing 3rd party tools. What we’re doing here is scanning the table 25 records at a time (the max we can batch execute), using some jmespath shenanigans in the –query to format it into batch execute statements, then passing that to the batch-execute-statement command. Lather, rinse, repeat until the size of bulk.json is 3 bytes or in other words "[]" an empty list.
Adjust as needed for your table name, sort key, range key (if any), and of course data types (they’re "S" string in this example).
This works…needs no extra tools…but it’s hardly efficient. If you want to get fancy, recoding it in python using a worker thread pool to pass the batches off to would likely gain it 100x speed.