Kittovski
Kittovski

Reputation: 187

GoLang Updating DynamoDB

When I attempt to update DynamoDB using the code below I get ValidationException: ExpressionAttributeValues contains invalid key: Syntax error; key: "approved"

I can't see why it is invalid

type TransactionUpdate struct {
    Approved bool `json:"approved"`
    Signer   int  `json:"signer"`
}

var TXkey Transaction
TXkey.TxID = sr.TxID
key, err := dynamodbattribute.MarshalMap(TXkey)

updateData, err := dynamodbattribute.MarshalMap(TransactionUpdate{
    Approved: true,
    Signer:   1,
})

updateString := "set approved=:a add signers :s"

input := &dynamodb.UpdateItemInput{
    Key:                       key,
    TableName:                 aws.String("Transactions"),
    UpdateExpression:          aws.String(updateString),
    ExpressionAttributeValues: updateData,
    ReturnValues:              aws.String("ALL_NEW"),
}

result, err := svc.UpdateItem(input)

dynamodbattribute.UnmarshalMap(result.Attributes, &tx)

Any help much appreciated

Upvotes: 2

Views: 5423

Answers (1)

Alex Pliutau
Alex Pliutau

Reputation: 21957

You should define what :a and :s are:

type TransactionUpdate struct {
    Approved bool `json:":a"`
    Signer   int  `json:":s"`
}

Upvotes: 3

Related Questions