2

I am trying to update both value1 and value2 item attributes in DynamoDb Table, but the UpdateExpression sets only one argument (value1). Trying to include both value1 and value2 (aws.String("set value1= :r, set value2= :c")) results in:

Got error calling UpdateItem: %s
ValidationException: Invalid UpdateExpression: Syntax error; token: "set", near: ", set 
HashValue" status code: 400, request id:******

How can I update more than one field in the Data Base item ?

--

func UpdateObject(obj MyObject) (string, error) {

sess := session.Must(session.NewSessionWithOptions(session.Options{
    SharedConfigState: session.SharedConfigEnable,
}))

// Create DynamoDB client
svc := dynamodb.New(sess)

// Update item in table Movies
tableName := "MyTable"

input := &dynamodb.UpdateItemInput{
    ExpressionAttributeValues: map[string]*dynamodb.AttributeValue{
        ":r": {
            N: aws.String(strconv.Itoa(obj.value1)),
        },
        ":c": {
            S: aws.String(obj.value2),
        },
    },
    TableName: aws.String(tableName),
    Key: map[string]*dynamodb.AttributeValue{
        "ThreatID": {
            N: aws.String(strconv.Itoa(obj.value3)),
        },
        "ThreatName": {
            S: aws.String(obj.value4),
        },
    },
    ReturnValues:     aws.String("UPDATED_NEW"),
    UpdateExpression: aws.String("set value1= :r"),
}

 //........

}

--

 type MyObject struct {
     value3 int
     value4 string
     value2 string
     value1 int
   }

1 Answer 1

3

Use this syntax:

aws.String("set value1= :r, value2= :c")

Reference: https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.UpdateExpressions.html

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

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.