Home How to remove all data from DynamoDB without for loop?
Reply: 2

How to remove all data from DynamoDB without for loop?

user3202457 Published in 2018-01-13 07:14:07Z

Suppose i have 100 data in DynamoDB then to remove all data i have to execute for loop .So is there any way to remove all data without for loop ?

let dynamoDbObjectMapper = AWSDynamoDBObjectMapper.default()

for var key in 0 ..<100 {

    let itemToDelete: CategoriesDB = CategoriesDB()
    itemToDelete._index = key

    dynamoDbObjectMapper.remove(itemToDelete, completionHandler:              
    {(error: Error?) -> Void in
        if let error = error {
            print(" Amazon DynamoDB Save Error: \(error)")
        print("A Category was deleted.")
Stu Reply to 2018-01-13 11:49:40Z

Ignoring the swift SDK for a moment, DynamoDB has the DeleteItem method to remove a single item from a table, but it also has a batch method.


In addition to DeleteItem, Amazon DynamoDB supports a BatchWriteItem action for deleting multiple items at the same time.

The problem is, I can't see a way to access BatchWriteItem through the swift SDK. Even if you could use BatchWriteItem, it can only take 25 items at a time, so you would still end up having to write a loop.

Sorry its not a more complete answer, but thought this might be useful. As far as I know there isn't a simple (single) method for doing this.

Vikdor Reply to 2018-01-13 12:28:11Z

If you want to remove all the data in a DynamoDB table, it is better to just delete the table and create it again as that wouldn't cost Write Capacity Units.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.316355 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO