I\'m a new user in boto3 and i\'m using DynamoDB.
I went through over the DynamoDB api and I couldn\'t find any method which tell me if a table is already e
You can use describe table API to determine whether the table exists.
Sample code:
from __future__ import print_function # Python 2/3 compatibility
import os
os.environ["TZ"] = "UTC"
import boto3
client = boto3.client('dynamodb', region_name='us-west-2', endpoint_url="http://localhost:8000")
response = client.describe_table(
TableName='Movies'
)
print(response)
If table exists:-
If table doesn't exists:-
You will get ResourceNotFoundException
botocore.errorfactory.ResourceNotFoundException: An error occurred (ResourceNotF oundException) when calling the DescribeTable operation: Cannot do operations on a non-existent table
Another way:-
Waits until this Table is exists. This method calls DynamoDB.Waiter.table_exists.wait() which polls. DynamoDB.Client.describe_table() every 20 seconds until a successful state is reached. An error is returned after 25 failed checks.
table.wait_until_exists()