What is the best way to check if table exists in DynamoDB?

后端 未结 6 2102
粉色の甜心
粉色の甜心 2021-02-19 22:28

What is the best way to check if table exists in DynamoDb?

I would appreciate it if the code would be in PHP.

Either active or not.

* Added late

6条回答
  •  迷失自我
    2021-02-19 22:55

    You can have a look at "describe_table" of the official PHP SDK. 400 means "does not exist" There is a pretty extensive example in the official documentation. Look at how it is used in the "delete" example, right at the bottom.

    http://docs.amazonwebservices.com/amazondynamodb/latest/developerguide/LowLevelPHPTableOperationsExample.html

    Here is the (stripped) example from the doc

    describe_table(array('TableName' => $table_name));
    
    if((integer) $response->status !== 400)
    {
        $error_type = $response->body->__type;
        $error_code = explode('#', $error_type)[1];
        if($error_code == 'ResourceNotFoundException')
        {
            echo "Table ".$table_name." exists.";
        }
    }
    ?>
    

提交回复
热议问题