GoLang更新DynamoDB

时间:2018-11-26 15:35:12

标签: go amazon-dynamodb

当我尝试使用下面的代码更新DynamoDB时,我得到了 ValidationException: ExpressionAttributeValues contains invalid key: Syntax error; key: "approved"

我看不到为什么无效

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)

非常感谢任何帮助

1 个答案:

答案 0 :(得分:0)

您应该定义:a:s是什么

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