2
votes

I am trying to use amazon dynamodb in my php application. I have setup the credential correctly. Now, I am trying to get the data from the Amazon DynamoDB to my application. But it is giving me an exception at the query line.

The full exception error is

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."}

Here is my code,

$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";
    }

The error is coming from the try-catch block. Can anybody give me the reason and solution of this error? Any suggestion for this error? Thanks in advance.

2
Are you running the dynamodb on local before executing the program ?notionquest
Yes, I am running the dynamodb on local before excuting the program not @notionquest . The dynamodb is working fine. But my database table is in aws console. Is it the problem?Mahbub
If the tables are in AWS region, you need to remove the endpoint parameter. 'endpoint' => 'localhost:8000'. The API will determine the endpoint based on the region specified.notionquest
I have removed the endpoint parameter. Now this is giving me this error @notionquest Unable to query: Error executing "Query" on "dynamodb.my-region.amazonaws.com"; AWS HTTP error: cURL error 60: SSL certificate problem: unable to get local issuer certificate (see curl.haxx.se/libcurl/c/libcurl-errors.html)Mahbub

2 Answers

4
votes

Please add the KeyConditionExpression with values.

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

You have to set a KeyConditions in your $params in order to query. This documentation can help you: https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/LegacyConditionalParameters.KeyConditions.html