It seems that this library not accept some attributes names in query method because are reserved.
PHP Fatal error: Uncaught exception 'Aws\DynamoDb\Exception\DynamoDbException' with message 'Error executing "Query" on "https://dynamodb.us-east-1.amazonawrror: `POST https://dynamodb.us-east-1.amazonaws.com` resulted in a `400 Bad Request` response:
{"__type":"com.amazon.coral.validate#ValidationException","message":"Invalid KeyConditionExpression: Attribute name is a (truncated...)
ValidationException (client): Invalid KeyConditionExpression: Attribute name is a reserved keyword; reserved keyword: hash - {"__type":"com.amazon.coral.valage":"Invalid KeyConditionExpression: Attribute name is a reserved keyword; reserved keyword: hash"}'
This is the query (done after all required init):
$response = $dynamodb->query([
'TableName' => 'informabene-invii',
'KeyConditionExpression' => 'hash = :v_hash',
'ExpressionAttributeValues' => [
':v_hash' => ['S' => 'a886b25d524217f5d6c9c8c008664733']
]
]);
As the error, my partition key is the key named "hash".
Can we consider this a bug of the library?
Thanks
@texano00 Thanks for bringing this to our notice.
This looks like its a bug with DynamoDb as I was able to reproduce the bug using the CLI.
We would recommend contacting the DynamoDb team directly so that you can track the bug. We will open an issue with DynamoDb as well.
@imshashank Thanks.
If the DynamoDB team reply me i update you here.
@imshashank
I've found a solution using the 'ExpressionAttributeNames' param.
This works!
$response = $dynamodb->query(array(
'TableName' => 'informabene-invii',
'Limit' => 1,
'ScanIndexForward' => false,
'KeyConditionExpression' => '#hash_doc = :v_hash',
'ExpressionAttributeValues' => array(
':v_hash' => array('S' => 'a886b25d524217f5d6c9c8c008664733')
),
'ExpressionAttributeNames' => array(
"#hash_doc" => "hash"
)
));
@texano00 That's great. We will notify the DynamoDb team anyway.
Not the DynamoDB team, but I can at least comment and explain the issue:
Certain attribute names are reserved, see the full list here. hash is one of these, which is causing your error.
@texano00's solution is the correct solution: use an ExpressionAttributeName to get around this limitation.
Most helpful comment
@imshashank
I've found a solution using the 'ExpressionAttributeNames' param.
This works!
$response = $dynamodb->query(array( 'TableName' => 'informabene-invii', 'Limit' => 1, 'ScanIndexForward' => false, 'KeyConditionExpression' => '#hash_doc = :v_hash', 'ExpressionAttributeValues' => array( ':v_hash' => array('S' => 'a886b25d524217f5d6c9c8c008664733') ), 'ExpressionAttributeNames' => array( "#hash_doc" => "hash" ) ));