3
votes

I'm trying to do a Scan to my DynamoDB table in NodeJS, but I'm having trouble with ExpressionAttributeValues because don't recognize the placeholder I defined in the filter expression. I pass as paremeter an object with the information I want, but sends me this error:

"Unexpected Key ':Value' found in params.ExpressionAttributeValues['atributeValues'], "code":"Unexpected parameter"

I don't know what's happening because if I put the content of the object as parameter it works perfectly so I'm stucked.

function Consult(cb, Filter, Event){
  var filterExpression = Filter+"= :Value";
  if(typeof Event[Filter] == "string"){
    //This is the object I'm trying to pass as parameter
    var attributeValues = {
      ":Value" : {"S" : Event[Filter] }
    }
  }else {
    //This is the object I'm trying to pass as parameter
    var attributeValues = {
      ":Value" : {"N" : Event[Filter] }
    }
  }
  dynamodb.scan({
      TableName: tableName,
      FilterExpression: filterExpression,
      ExpressionAttributeValues:{ ":Value" : {"S" : Event[Filter] } } //This Works
      ExpressionAttributeValues:{ attributeValues } //This don't and I don't know why
  }, function(err, data){
      if(err){
          console.log(err);
          cb(err, null);
      } else {
          cb(null, data.Items);
      }
  });
}
2
you have not used ExpressionAttributeNames in scan query. - arjun kori
FilterExpression: 'contains(#postid,:val)', ExpressionAttributeNames: { '#emmp': 'postId' }, ExpressionAttributeValues: { ':val': { 'S': postid } } - arjun kori

2 Answers

3
votes

Please change the code as mentioned below. No need to wrap the attributeValues with curly braces again.

ExpressionAttributeValues: attributeValues 
-1
votes

This is not a direct answer (I can't share formatted code in a comment), but a suggestion how to debug this:

var params = {};
params.TableName = tableName;
params.FilterExpression = filterExpression;
params.ExpressionAttributeValues = { attributeValues };
console.log(JSON.stringify(params));
dynamodb.scan(params, function(err, data){
....
}

The output of the console.log will show you exactly the parameters for the scan. You can compare both alternatives for ExpressionAttributeValues. This will give you a hint about what's wrong.