8
votes

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 ?

1

1 Answers

4
votes

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'});