Reputation: 2677
I wants to delete all the existing tables in my database in DynamoDb?
Is there any way to do it?
Upvotes: 6
Views: 15817
Reputation: 11
To delete all the DynamoDB tables having a specific keyword in their names, simply run the following CLI commands:
tableList=$(aws dynamodb list-tables | jq .'TableNames[]' -r | grep tableNameKeyword)
for table in $tableList; do aws dynamodb delete-table --table-name $table ; done
Upvotes: 1
Reputation: 13056
The new UI console (2020) now allows you to select multiple tables and delete.
Upvotes: 4
Reputation: 443
Javascript to delete all tables
var AWS = require("aws-sdk")
AWS.config.update({
region: "us-west-2",
endpoint: process.env.DYNAMODB_URL
})
var dynamodb = new AWS.DynamoDB();
dynamodb.listTables({}, function(err, data) {
if (err) console.error(err, err.stack)
for (tableName of data.TableNames) {
dynamodb.deleteTable({TableName: tableName}, function(err, data) {
if (err) console.error(err, err.stack)
else console.log('Deleted', tableName)
})
}
})
Upvotes: 4
Reputation: 61
You can delete table using below code.
var params = {
TableName: 'table-name',
};
dynamodb.deleteTable(params, function(err, data) {
if (err) ppJson(err); // an error occurred
else ppJson(data); // successful response
});
Upvotes: 6
Reputation: 1812
You can use aws cli to delete all tables, may be except one table.
aws dynamodb list-tables --profile your_profile | jq .'TableNames[]' -r | grep -v table_you_dont_want_to_delete | xargs -ITABLE -n 1 aws dynamodb delete-table --table-name TABLE --profile your_profile
Upvotes: 13
Reputation: 937
require 'json'
tables=JSON.parse(`aws dynamodb list-tables`)["TableNames"]
tables.each do |table|
`aws dynamodb delete-table --table-name #{table}`
sleep 2 # Only 10 tables can be created, updated, or deleted simultaneously
puts "#{table} deleted"
end
Upvotes: 1
Reputation: 47319
You have 2 options:
ListTables
(multiple calls if pagination is needed), iterate through the resulting TableNames, and call DeleteTable
for each one.Upvotes: 5