Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DynamoDB : SET list_append not working using aws sdk

I need to append a string to a string set in a dynamodb table using the corresponding key. This is the Update expression I use to do updateItem :

  var params = {     "TableName" : tableName,     "Key": {       "ID": {         S: "20000"       }     },     "UpdateExpression" : "SET #attrName = list_append(#attrName, :attrValue)",     "ExpressionAttributeNames" : {       "#attrName" : "entries"     },     "ExpressionAttributeValues" : {       ":attrValue" : {"SS":["000989"]}     }   }; 

This works when I do updateItem() using the aws cli. But when using aws-sdk in nodejs, I am getting the error:

Invalid UpdateExpression: Incorrect operand type for operator or function; operator or function: list_append, operand type: M\n 

Any help? Thanks

like image 201
void Avatar asked Oct 22 '15 10:10

void


1 Answers

list_append can be read as a "concatenate" operation. You just give it two lists.

"UpdateExpression" : "SET #attrName = list_append(#attrName, :attrValue)", "ExpressionAttributeNames" : {   "#attrName" : "entries" }, "ExpressionAttributeValues" : {   ":attrValue" : ["000989"] } 

It's worth remembering that lists (and maps) in DynamoDB are not typed and can store arbitrary data.

Side note: Armed with this knowledge, the documentation on appending to the beginning of the list now makes sense:

list_append (operand, operand)

This function evaluates to a list with a new element added to it. You can append the new element to the start or the end of the list by reversing the order of the operands.

like image 175
chetbox Avatar answered Sep 23 '22 04:09

chetbox