php - 400 错误请求响应 : KeyConditionExpression parameter must be specified in the request

标签 php amazon-web-services amazon-s3 amazon-dynamodb aws-sdk

我正在尝试在我的 php 应用程序中使用 amazon dynamodb。我已正确设置凭据。现在,我正在尝试将数据从 Amazon DynamoDB 获取到我的应用程序。但它在查询行给了我一个异常(exception)。

完整的异常错误是

Unable to query: Error executing "Query" on "https://dynamodb.my-region.amazonaws.com"; AWS HTTP error: Client error: POST https://dynamodb.my-region.amazonaws.com resulted in a 400 Bad Request response: {"__type":"com.amazon.coral.validate#ValidationException","message":"Either the KeyConditions or KeyConditionExpression (truncated...) ValidationException (client): Either the KeyConditions or KeyConditionExpression parameter must be specified in the request. - {"__type":"com.amazon.coral.validate#ValidationException","message":"Either the KeyConditions or KeyConditionExpression parameter must be specified in the request."}

这是我的代码,

$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 block 。任何人都可以告诉我这个错误的原因和解决方案吗? 对这个错误有什么建议吗?提前致谢。

最佳答案

请添加带有值的KeyConditionExpression

 $params = [
        'TableName' => $tableName,
        'KeyConditionExpression' => 'yourHashKey = :v_hash'
        'ExpressionAttributeValues' =>  array (
                  ':v_hash'  => array('S' => 'Hash_Value')
             )
    ];

关于php - 400 错误请求响应 : KeyConditionExpression parameter must be specified in the request,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48168007/

相关文章:

PHP 多个 __autoload 函数*不*使用 spl_register_autoload?

php - 我的 PHP 包含数据库连接有什么问题?

amazon-web-services - 无法上传到AWS S3

ruby-on-rails - 如何根据当前Rails环境设置回形针的存储机制?

php - 如何使用 PHP foreach 循环将多个嵌套的 json 对象插入到 mysql 中?

php - wordpress 在 wp admin 中也采用了 thme 的风格

amazon-web-services - 访问VPC中的RDS实例时,外部可访问的IP地址在哪里?

amazon-web-services - AWS API 网关自定义域

ruby - 将文件从 Cloudfiles 移植到 S3

java - 轮询 S3 中的对象时等待来自池的连接超时