Trying to use KeyConditionExpression as per the dynamodb api document using nodejs sdk. KeyConditionExpression is not supported with nodejs SDK.
Here is what i did
Created a Table with Hash and Range.
Table : TABLE1
Hash Attribute Name : Provider ( String)
Range Attribute Key : ScheduledEndTime ( Number ) // In Milli Seconds
Here is payload to trigger dynamo DB query:
{
TableName: 'TABLE1',
ConsistentRead: true,
Select: "ALL_ATTRIBUTES",
KeyConditionExpression: 'Provider = :v_provider AND ScheduledEndTime > :v_scheduledEndTime',
ExpressionAttributeValues: {
":v_provider": {
S: "amazon"
},
":v_scheduledEndTime": {
N: "10"
}
}
};
But, the above payload thrown below errors
[Error: MultipleValidationErrors: There were 2 validation errors:
* MissingRequiredParameter: Missing required key 'KeyConditions' in params
* UnexpectedParameter: Unexpected key 'KeyConditionExpression' found in params]
[Error: MultipleValidationErrors: There were 2 validation errors:
* MissingRequiredParameter: Missing required key 'KeyConditions' in params
* UnexpectedParameter: Unexpected key 'KeyConditionExpression' found in params]
As per the document, if we use KeyConditionExpression, SDK should not consider the KeyConditions key and I tried with latest nodejs sdk as well. Is there any thing wrong in the payload pattern ?
Querying is a very powerful operation in DynamoDB. It allows you to select multiple Items that have the same partition ("HASH") key but different sort ("RANGE") keys.
For faster response times, design your tables and indexes so that your applications can use Query instead of Scan . (For tables, you can also consider using the GetItem and BatchGetItem APIs.) Alternatively, design your application to use Scan operations in a way that minimizes the impact on your request rate.
DynamoDB does support the complex condition on FilterExpression . Perfectly fine.
The Query operation allows you to limit the number of items that it reads. To do this, set the Limit parameter to the maximum number of items that you want. For example, suppose that you Query a table, with a Limit value of 6 , and without a filter expression.
I think some places (Lambda in particular) give you the wrong version of the API by default. When I was running into this problem, replacing my dynamo instance with the following fixed the problem:
var AWS = require("aws-sdk");
var dynamo = new AWS.DynamoDB({apiVersion: '2012-08-10'});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With