duanliangman5398 2018-11-26 15:35
浏览 133
已采纳

GoLang更新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

  • 写回答

1条回答 默认 最新

  • donglu8549 2018-11-26 15:45
    关注

    You should define what :a and :s are:

    type TransactionUpdate struct {
        Approved bool `json:":a"`
        Signer   int  `json:":s"`
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?