检查表在DynamoDB中是否存在的最佳方法是什么? [英] What is the best way to check if table exists in DynamoDB?

查看:260
本文介绍了检查表在DynamoDB中是否存在的最佳方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

检查表是否存在于DynamoDb中的最佳方法是什么?

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

如果代码在PHP中,我将不胜感激。

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

是否处于活动状态。

* 稍后作为示例添加到错误代码为400的各种情况下

* Added later as an example to various cases for error code 400

检查表是否存在非常容易,它可以具有以下
TableStatus之一=>创建,活动,删除或更新

It's very easy to check if the table exist, it can have one of the following TableStatus => CREATING, ACTIVE, DELETING or UPDATING

但如果出现错误400,则可能意味着不止一件事。

but in case i get error 400 it can mean more than one thing.

1)错误地将空字符串作为表名发送。

1) sent null string as a table name by mistake.

[x-aws-body] => { TableName:}

[x-aws-body] => {"TableName":""} )

[body] => CFSimpleXML Object
    (
        [__type] => com.amazon.coral.validate#ValidationException
        [message] => The paramater 'tableName' must be at least 3 characters long and at most 255 characters long
    )

[status] => 400

2)发送到DynamoDB的命令中的语法错误,例如用tabel_name代替table_name。

2) syntax error in the command sent to DynamoDB, for example writting tabel_name instead of table_name.

[x-aws-body] => { TabelName: test7}

[x-aws-body] => {"TabelName":"test7"} )

[body] => CFSimpleXML Object
    (
        [__type] => com.amazon.coral.validate#ValidationException
        [message] => The paramater 'tableName' is required but was not present in the request
    )

[status] => 400

3)我猜但没有检查,如果我同时超过了规定

3) I would guess but didn't check, if I exceed at that same time the provisioned capacity on the table.

推荐答案

您可以查看官方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.";
    }
}
?>

这篇关于检查表在DynamoDB中是否存在的最佳方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆