Reputation: 716
I am using Dynamodb for an api service I am writing. I started writing tests and I found that there is no command(or query) which destroys all the "items" in a table. I am using vogels to access dynamodb.
I usually clean the table before every test. How do I do that given that there is no single command( or query) that deletes all the items in a table?
If I delete each item one by one the tests start executing before all the items get deleted.
Upvotes: 4
Views: 532
Reputation: 39176
The CRUD operation is atomic in DynamoDB. There is no API available to delete all the items in the DynamoDB table.
Solution 1:
The best recommended solution is to delete the table and recreate it.
Solution 2:
Use batchWriteItem with DeleteRequest for deleting multiple items in one go. The maximum number of requests on batch write is 25 items.
Wait for:-
After executing the delete table, please wait until the resource is not available. Similarly, after executing the create table, you need to wait until the resource is available.
var params = {
TableName: 'STRING_VALUE' /* required */
};
dynamodb.waitFor('tableNotExists', params, function(err, data) {
if (err) console.log(err, err.stack); // an error occurred
else console.log(data); // successful response
});
Waits for the tableNotExists state by periodically calling the underlying DynamoDB.describeTable() operation every 20 seconds (at most 25 times).
Upvotes: 1