How to check if DynamoDB table exists?

前端 未结 6 2248
情话喂你
情话喂你 2021-02-01 01:06

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

6条回答
  •  温柔的废话
    2021-02-01 01:26

    Note that it kind of depends on if you are using client or resource. If you use boto3.client(), you can use the 3 methods the accepted answer suggested. If you are using boto3.resource(), you can only use dynamodb_resource.create_table() and check exceptions.

    try:
        table = dynamodb_resource.create_table(
            ...
        )
        table.meta.client.get_waiter('table_exists').wait(TableName=your_table_name)
    except ResourceInUseException:
        # do sth here
    

提交回复
热议问题