squeekyDave
squeekyDave

Reputation: 962

Update key value of an object inside Dynamo DB

I have the following object saved into Dynamo DB.

   const obj =  {
        data:{
            src:"s3://some_bucket_name/folder/foo.html",
            dest:"s3://some_bucket_name/folder/bar.pdf"
        },
        op: "someFunc",
        status: "not started"

    }

This works, and my data is being saved in DynamoDB. However, I want to update the status of the data in another place and change it to started.

This is the code I have for updating the status but it doesnt work. It says "unexpected key found in params.Key[status]"

          const params = {
                TableName: 'tableName',
                Key: {
                    "status": record.dynamodb.Keys.Document.S
                },
                UpdateExpression: "SET started = :started",
                ExpressionAttributeValues: {
                    ":started": "started"
                },
                ReturnValues: "UPDATED_NEW"
            }


          db.updateItem(params).promise()
            .then(data => console.log(data, 'updated data data'))
            .catch(err => console.log(err, 'err updating item'))

I checked other examples on SO and online but I couldnt make it work, can anyone point me what I am doing wrong?

Upvotes: 0

Views: 669

Answers (1)

Mark B
Mark B

Reputation: 200446

Key should reference the primary key attribute of your table. I don't believe the status field is the table's primary key.

The status field belongs in the UpdateExpression like

UpdateExpression: "SET status = :started",

Upvotes: 1

Related Questions