Dimitre Novatchev
Dimitre Novatchev

Reputation: 243469

How to find DynamoDB all table names that match a pattern?

I need to find all DynamoDB existing table names that start with a given string.

What is the best/recommended way to do this?

I need to do this, for example to find all tables, whose name starts with "__Test__" and then delete all these tables.

Upvotes: 2

Views: 2352

Answers (1)

mkobit
mkobit

Reputation: 47249

To do it programmatically, you would have to do it in these steps.

  1. Call the ListTables API
  2. Go through all of the TableNames in the response
  3. Call DeleteTable on any table that has a name matching the "__Test__" pattern
  4. If the LastEvaluatedTableName is present in the response, repeat steps 1-3 setting the ExclusiveStartTableName for pagination

There is also some requirements for calling DeleteTable regarding the table state. From the documentation:

The DeleteTable operation deletes a table and all of its items. After a DeleteTable request, the specified table is in the DELETING state until DynamoDB completes the deletion. If the table is in the ACTIVE state, you can delete it. If a table is in CREATING or UPDATING states, then DynamoDB returns a ResourceInUseException. If the specified table does not exist, DynamoDB returns a ResourceNotFoundException. If table is already in the DELETING state, no error is returned.

If you only need to do this to a few tables and not recurring, you can go to the AWS DynamoDB console and (after selecting the right region) delete the table directly in the UI.

Upvotes: 3

Related Questions