- Newest
- Most votes
- Most comments
There is no direct single command to delete all items from a DynamoDB table without using a program. Your options are:
- Delete and recreate the table using the AWS CLI:
aws dynamodb delete-table --table-name YourTableName
Then recreate the table with the same schema. This is the most efficient approach if you want to remove all items.
-
Scan then Delete, this would require you to read all items in the table, and call DeleteItem for each returned result, or with BatchWriteItem in batches of 25.
-
For batch operations with PartiQL, you would need to specify each item's key:
aws dynamodb batch-execute-statement --statements '[{"Statement": "DELETE FROM \"YourTableName\" WHERE partitionKey = ?", "Parameters": [{"S": "value1"}]}, {"Statement": "DELETE FROM \"YourTableName\" WHERE partitionKey = ?", "Parameters": [{"S": "value2"}]}]'
Note that options 2 and 3 require you to know the keys or attributes of the items you want to delete, which means you would typically need to scan the table first to get this information.
The most straightforward approach is to delete and recreate the table if you want to remove all items.
Sources
Delete DynamoDB data using PartiQL DELETE statements with an AWS SDK - Amazon DynamoDB
Delete DynamoDB data using PartiQL DELETE statements with an AWS SDK - AWS SDK Code Examples
Use DeleteTable with an AWS SDK or CLI - Amazon DynamoDB
answered a year ago
If you prefer not to write code or scripts, another option is using a desktop GUI client like DocKit (open source, free) which has a truncate table feature — it handles the scan-then-delete loop for you behind the scenes. Steps:
- Connect to your Dynamo
- DB table in DocKit.
- Open the table in the Manage panel.
- Use the truncate option to delete all items
This is essentially the same scan + BatchWriteItem approach from the accepted answer, but without you having to write or run any code. Useful if you need to do this occasionally and don't want to maintain a script.
That said, if you need to do this frequently or at scale (millions of items), the delete and recreate table approach from the accepted answer is still faster — truncation via scan has to paginate through everything, which takes time on large tables.
Download: geekfun.club/products/dockit (https://www.geekfun.club/products/dockit)
Source: github.com/geek-fun/dockit (https://github.com/geek-fun/dockit)
Disclosure: I'm the founder of GEEKFUN, the open-source community behind DocKit.
answered 4 months ago
Relevant content
asked 5 years ago
asked 3 years ago
- AWS OFFICIALUpdated 3 years ago
