3

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. Commented Sep 14, 2016 at 13:50
  • FilterExpression: 'contains(#postid,:val)', ExpressionAttributeNames: { '#emmp': 'postId' }, ExpressionAttributeValues: { ':val': { 'S': postid } } Commented Sep 14, 2016 at 13:54

2 Answers 2

3

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

ExpressionAttributeValues: attributeValues 
Sign up to request clarification or add additional context in comments.

1 Comment

Oh man. Thanks for the time. I didn't check the answer until today, I solved it just the way you did. Appreciate it
-1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.