0

I am interested in receiving all the data located in my DynamoDB table and most efficiently clear the table afterwards.

I have seen how to delete an item and retrieve it concurrently in concurrency - DynamoDB - how to retrieve and delete (pop) an item?. I have also seen batch deletion in database - What is the recommended way to delete a large number of items from DynamoDB?.

Ideally I would like to concurrently clear the table and retrieve the data. Is there a better way to do this?

John Rotenstein
  • 241,921
  • 22
  • 380
  • 470

2 Answers2

0

If you subscribe a lambda function to the dynamo db stream for the table, you can process items as they are deleted (technically, it will show up in the stream shortly after the item is deleted).

Matthew Pope
  • 7,212
  • 1
  • 28
  • 49
0

You could retrieve all rows from the table, put it in a list and then send the list to dynamodbs delete method. This works for me:

 public async Task DeleteAllReadModelEntitiesInTable()
{
    List<ReadModelEntity> readModels;

    var conditions = new List<ScanCondition>();
    readModels = await _context.ScanAsync<ReadModelEntity>(conditions).GetRemainingAsync();

    var batchWork = _context.CreateBatchWrite<ReadModelEntity>();
    batchWork.AddDeleteItems(readModels);
    await batchWork.ExecuteAsync();
}
Mohammad
  • 1,498
  • 2
  • 12
  • 15