Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Issues with dynamodb query with KeyConditionExpression

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 ?

like image 343
Santhosh Nagulanchi Avatar asked Jul 04 '15 10:07

Santhosh Nagulanchi


People also ask

Is DynamoDB good for querying?

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.

How can I improve my DynamoDB Query performance?

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.

Does DynamoDB support complex queries?

DynamoDB does support the complex condition on FilterExpression . Perfectly fine.

What does the Query operation in Amazon DynamoDB allow you to do?

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.


1 Answers

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'}); 
like image 144
Rob Simmons Avatar answered Oct 19 '22 03:10

Rob Simmons