roeygol roeygol -4 years ago 586
Python Question

How to check if DynamoDB table exists?

I'm a new user in boto3 and i'm using


I went through over the DynamoDB api and I couldn't find any method which tell me if a table is already exists.

What is the best approach dealing this issue?

Should I try to create a new table and wrap it using try catch ?

Answer Source

From reading the documentation, I can see that there are three methods by which you can check if a table exists.

  1. The CreateTable API throws an error ResourceInUseException if the table already exists. Wrap the create_table method around try except to catch this
  2. You can use the ListTables API to get the list of table names associated with the current account and endpoint. Check if the table name is present in the list of table names you get in the response.
  3. The DescribeTable API will throw an error ResourceNotFoundException if the table name you request doesn't exist.

To me, the first option sounds better if you just want to create a table.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download