首页  >  文章  >  后端开发  >  适用于 Dynamodb 的 Golang SDK:ReturnValuesOnConditionCheckFailure 不返回有关条件chcekfailure 发生时的条件的详细信息

适用于 Dynamodb 的 Golang SDK:ReturnValuesOnConditionCheckFailure 不返回有关条件chcekfailure 发生时的条件的详细信息

PHPz
PHPz转载
2024-02-10 18:45:18541浏览

适用于 Dynamodb 的 Golang SDK:ReturnValuesOnConditionCheckFailure 不返回有关条件chcekfailure 发生时的条件的详细信息

php小编小新为您介绍适用于Dynamodb的Golang SDK中的一个重要特性:ReturnValuesOnConditionCheckFailure。这个特性在条件检查失败时不会返回关于条件的详细信息,从而保护了敏感数据。使用这个特性,开发者可以更加安全地处理条件检查失败的情况,并且提高应用程序的可靠性。在本文中,我们将深入探讨这个特性的用法和优势,帮助开发者更好地理解和应用于实际项目中。

问题内容

我正在使用 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,则此功能尚不存在

以上是适用于 Dynamodb 的 Golang SDK:ReturnValuesOnConditionCheckFailure 不返回有关条件chcekfailure 发生时的条件的详细信息的详细内容。更多信息请关注PHP中文网其他相关文章!

声明:
本文转载于:stackoverflow.com。如有侵权,请联系admin@php.cn删除