2

我正在使用AWS PHP 开发人员指南 中描述的方法查询 DynamoDB 表。

我传递给 Dynamo 连接的数组如下所示:

Array(
    [ConsistentRead] => false
    [TableName] => bbq_lol_test
    [KeyConditions] => Array(
            [stinky_cheese] => Array(
                    [ComparisonOperator] => EQ
                    [AttributeValueList] => Array(
                            [S] => camembert)

                )
        )
)

如您所见,它与示例使用的格式完全相同,但Type枚举除外(它只是一个字符串)。

$connection->query使用上述数组作为参数执行时,出现以下异常:

Guzzle\Service\Exception\ValidationException: 
Validation errors: [KeyConditions][stinky_cheese][AttributeValueList][S][AttributeValue] must be of type object

这很奇怪,因为堆栈跟踪中的数组似乎很好:

Aws/Common/Client/AbstractClient.php(103): Guzzle\Service\Client->__call("Query", array(array("ConsistentRead" => false, "TableName" => "bbq_lol_test", "KeyConditions" => array("stinky_cheese" => array("ComparisonOperator" => "EQ", "AttributeValueList" => array("S" => "camembert"))))))

确实在该字段上有一个索引stinky_cheese(因为我正在使用查询)。我可能在做一些愚蠢的事情,但我现在似乎无法弄清楚。任何帮助将不胜感激 - 谢谢!

4

1 回答 1

5

有两个问题。

首先,AttributeValueList应该是一个数组数组,而不是单个数组,从这个开始:

[AttributeValueList] => Array([S] => camembert)

对此:

[AttributeValueList] => Array(Array([S] => camembert))

因为可以在那里添加更多的东西,像这样:

[AttributeValueList] => Array(Array([S] => camembert), Array([S] => bleu))

第二个问题是我总是必须使用主哈希键进行查询,而我没有这样做。

于 2013-07-12T18:49:58.607 回答