I would like to update an item under certain conditions and then I would like to know whether the item was updated when UpdateItem returns.
The documentation seems contradictory to me.
On this page: http://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_UpdateItem.html in the "Conditional Update" example it says "All of the item's attributes, as they appear after the update, are returned in the response."
On this page: https://godoc.org/github.com/aws/aws-sdk-go/service/dynamodb#UpdateItemOutput it says that Attributes is "A map of attribute values as they appeared before the UpdateItem operation"
I don't really want either of these. What I want is a bool that says whether or not there was an update.
This is where my brain is at now:
out, err := db.DynamoDB.UpdateItem(&dynamodb.UpdateItemInput{
TableName: tableName,
Key: map[string]*dynamodb.AttributeValue{
"KeyName": {S: aws.String(keyname)},
},
ExpressionAttributeNames: map[string]*string{
"#lock": aws.String("Lock"),
},
ExpressionAttributeValues: map[string]*string{
":now": aws.String(compfmt(time.Now())),
":promise": aws.String(compfmt(time.Now().Add(30 * time.Second))),
},
ConditionExpression: aws.String("attribute_not_exist(#lock) OR :now > #lock"),
UpdateExpression: aws.String("SET #lock = :promise"),
})