且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

检查表在DynamoDB中是否存在的***方法是什么?

更新时间:2021-11-06 22:51:51

您可以查看官方PHP的 describe_table SDK。 400 表示 不存在。官方文档中有一个非常详尽的示例。在底部的删除示例中查看它的用法。

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

这里是(摘录)来自doc的示例

Here is the (stripped) example from the doc

<?php
require_once dirname(__FILE__) . '/sdk/sdk.class.php';

$dynamodb = new AmazonDynamoDB();
$table_name = 'ExampleTable';
$response = $dynamodb->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.";
    }
}
?>