我正在使用 golang sdk https://pkg.go.dev/github.com/aws/[email protected]/ 进行调试条件检查错误并找到有关单个写入操作失败的原因的信息,但我只能看到错误 Message_:“条件请求失败”。在 UpdateItemInput 中使用参数 ReturnValuesOnConditionCheckFailure: ALL_OLD 时,未提供有关具体原因的其他信息。对于 TransactWriteItems,使用相同参数时我可以看到条件检查失败的具体原因。如何获取单个写入操作的这些详细信息?参考:https://aws.amazon.com/about-aws/whats-new/2023/06/amazon-dynamodb-cost-failed-conditional-writes 我正在使用的语法:
input := &dynamodb.UpdateItemInput{ TableName: aws.String("DummyTable"), Key: keyAttr, ExpressionAttributeValues: updateExpr.Values(), ExpressionAttributeNames: updateExpr.Names(), ConditionExpression: updateExpr.Condition(), ReturnValues: aws.String(dynamodb.ReturnValueAllOld), UpdateExpression: updateExpr.Update(), ReturnValuesOnConditionCheckFailure: aws.String(dynamodb.ReturnValuesOnConditionCheckFailureAllOld), } output, err := dl.ddbI.UpdateItem(input)
该项目应位于错误组件内,通常位于 error.response.Item
中。
例如在Python中:
except botocore.exceptions.ClientError as error: if error.response["Error"]["Code"] == "ConditionalCheckFailedException": print("The conditional expression is not met") current_value = error.response.get("Item")
注意:如果您使用的是 DynamoDB Local,则此功能尚不存在