I have been trying to figure out how to update an item in dynamoDB but have not had any success.
I know how to add and item and remove an item but not update.
It looks like you are trying to update an item by using an Expression, and in this case, your UpdateExpression is incorrect. Both the ExpressionAttributeNames
and ExpressionAttributeValues
are used for placeholder substitution in your expression.
I think your code would look something like this, if you want to set an attribute for an item:
dynamoDB.updateItem({
"TableName" : "exampleTable",
"Key" : {
"hashAttributeName" : {
"S" : "thing_ID"
}
},
"UpdateExpression" : "SET #attrName =:attrValue",
"ExpressionAttributeNames" : {
"#attrName" : "SessionID"
},
"ExpressionAttributeValues" : {
":attrValue" : {
"S" : "maybe this works"
}
}
});
This will update an item that looks like this:
{
"Item":{
"hashAttributeName":"thing_ID"
}
}
To this:
{
"Item":{
"hashAttributeName" : "thing_ID",
"SessionID" : "maybe this works"
}
}