What is the recommended way to delete a large number of items from DynamoDB?

前端 未结 7 2158
情歌与酒
情歌与酒 2020-11-29 21:51

I\'m writing a simple logging service in DynamoDB.

I have a logs table that is keyed by a user_id hash and a timestamp (Unix epoch int) range.

When a user of

7条回答
  •  北海茫月
    2020-11-29 22:36

    My approach to delete all rows from a table i DynamoDb is just to pull all rows out from the table, using DynamoDbs ScanAsync and then feed the result list to DynamoDbs AddDeleteItems. Below code in C# works fine for me.

            public async Task DeleteAllReadModelEntitiesInTable()
        {
            List readModels;
    
            var conditions = new List();
            readModels = await _context.ScanAsync(conditions).GetRemainingAsync();
    
            var batchWork = _context.CreateBatchWrite();
            batchWork.AddDeleteItems(readModels);
            await batchWork.ExecuteAsync();
        }
    

    Note: Deleting the table and then recreating it again from the web console may cause problems if using YAML/CloudFormation to create the table.

提交回复
热议问题