How to check if DynamoDB table exists?

前端 未结 6 2302
情话喂你
情话喂你 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:29

    Alternate approach if you do not want to use boto3.client but only boto3.resource:

    import boto3
    
    database = boto3.resource('dynamodb', endpoint_url="http://localhost:8000")    
    
    table_name  = 'MyTable'
    table_names = [table.name for table in database.tables.all()]
    
    if table_name in table_names:
        print('table', table_name, 'exists')
    

提交回复
热议问题