2
votes

I'm trying to learn AWS DynamoDB and ran into a seemingly simple looking issue that I can't figure out.

I'm using Dynalite running on nodejs locally. The error is as follows;

{ [ValidationException: Either the KeyConditions or KeyConditionExpression parameter must be specified in the request.] message: 'Either the KeyConditions or KeyConditionExpression parameter must be specified in the request.', code: 'ValidationException', time: Mon Dec 21 2015 17:31:47 GMT+0200 (SAST), requestId: 'RHDFVDXQTI0VZUIRJSLGRZXJFQJQYWGJOGS0B4MUDSX3H3JSVWNR', statusCode: 400, retryable: false, retryDelay: 0 }

My table is created as follows(code is stripped down for brevity);

var params = {
    TableName : "test",
    KeySchema: [       
      { AttributeName: "email", KeyType: "HASH" },  
      { AttributeName: "date", KeyType: "RANGE" }
    ],
    AttributeDefinitions: [       
        { AttributeName: "email", AttributeType: "S" },
        { AttributeName: "date", AttributeType: "N" }
    ],
    ProvisionedThroughput: {       
        ReadCapacityUnits: 1, 
        WriteCapacityUnits: 1
    }
}

dynamodb.createTable(params, function(err, data) {
    if (err) { console.log(JSON.stringify(err, null, 2)) }
    } else   { console.log(JSON.stringify(data, null, 2)) }
})

Test data is loaded with the following;

var params = { 
    TableName: 'test',
        Item: {
            "email":   lowerCasedEmail,
            "date":    date,                                                
            "amount":  amount,
        }
    }

  dynamodbDoc.put(params, function(err, data) {
     if (err){
       console.log(JSON.stringify(err, null, 2))
     } else {
        console.log(JSON.stringify(data, null, 2))
     }
  })

And then the failing query is as follows;

var params = {
    TableName: "test",    
    KeyConditionExpression: "email = :testmail",
    ExpressionAttributeValues: {
      ":testmail": "[email protected]"
    }
}

dynamodbDoc.query(params, function(err, data) {
   if (err) { console.log(err) } 
   else {
      if (Object.keys(data).length === 0) {
             console.log('Nothing found.')
      } else { console.log(data) }
   }
 })
1

1 Answers

2
votes

I found the problem. Dynalite doesn't handle KeyConditionExpression correctly.