我想在我的php应用程序中使用amazon dynamodb。我已正确设置凭据。现在,我正在尝试将Amazon DynamoDB中的数据提供给我的应用程序。但它在查询行中给了我一个例外。
完整的异常错误是
无法查询:执行错误"查询" on" https://dynamodb.my-region.amazonaws.com&#34 ;; AWS HTTP错误:客户端错误:
POST https://dynamodb.my-region.amazonaws.com
导致400 Bad Request
响应:{" __ type":" com.amazon.coral.validate#ValidationException",& #34; message":" KeyConditions或KeyConditionExpression(截断...)ValidationException(client):必须在请求中指定KeyConditions或KeyConditionExpression参数。 - {" __ type":" com.amazon.coral.validate#ValidationException"," message":"必须指定KeyConditions或KeyConditionExpression参数在请求中。"}
这是我的代码,
$sdk = new Aws\Sdk([
'region' => 'my region',
'version' => 'latest',
'credentials' => [
'key' => 'my key',
'secret' => 'my secret key'
],
'DynamoDb' => [
'region' => 'my region',
],
]);
$dynamodb = $sdk->createDynamoDb();
$marshaler = new Marshaler();
$tableName = 'My Table Name';
$params = [
'TableName' => $tableName
];
try {
$result = $dynamodb->query($params);
} catch (DynamoDbException $e) {
echo "Unable to query:\n";
echo $e->getMessage() . "\n";
}
错误来自try-catch块。任何人都可以告诉我这个错误的原因和解决方案吗? 有任何关于此错误的建议吗?提前谢谢。
答案 0 :(得分:1)
请添加KeyConditionExpression
值。
$params = [
'TableName' => $tableName,
'KeyConditionExpression' => 'yourHashKey = :v_hash'
'ExpressionAttributeValues' => array (
':v_hash' => array('S' => 'Hash_Value')
)
];
答案 1 :(得分:0)
您必须在$ params中设置KeyConditions才能进行查询。本文档可以帮助您:https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/LegacyConditionalParameters.KeyConditions.html