0

How can I clear all items from a DynamoDb table without deleting and recreating the table? The table is created/defined using CloudFormation so I don't want to duplicate that concern in business code.

I'm using TypeScript/NodeJs.

This question says to scan every item, chunk into blocks of 25, then delete each item using BatchWrite, however:

  • It seems like I'm writing a lot of code do something that's presumably quite common.
  • Scan returns items with their type, which I need to strip out, which involve a copy for every item, so again I'm writing a lot of code do something that's presumably quite common.

Is there a better way? Am I missing something?

eoinmullan
  • 1,157
  • 1
  • 9
  • 32
  • There's no better way. I have been working with dynamo tables for years and I have never wanted for this functionality nor can I think of a legitimate use case. – Lev Kuznetsov Nov 30 '20 at 21:36
  • 2
    OP points out their reasoning: "The table is created/defined using CloudFormation so I don't want to duplicate that concern in business code." Are you suggesting that this isn't a legitimate concern? If so, is there a better way to achieve it? – Evan Trimboli Nov 30 '20 at 21:53

1 Answers1

2

Nope, those are your only two options:

  1. delete and recreate the table
  2. (Batch) Delete each item in the table

Why is this needed?

If this really is a "common need" for your application.. Have you considered more ephemeral storage, such as Elasticache?

What about DDB's ability to automatically expire and removed items via TTL functionality?

Charles
  • 21,637
  • 1
  • 20
  • 44