Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DynamoDB Scan, Error in ExpressionAttributeValues Unexpected Key NodeJS

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);
      }
  });
}
like image 922
Camarbro Avatar asked Jan 01 '26 14:01

Camarbro


1 Answers

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

ExpressionAttributeValues: attributeValues 
like image 118
notionquest Avatar answered Jan 03 '26 05:01

notionquest



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!