首页 > 后端开发 > Golang > 正文

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

PHPz
发布: 2024-02-10 18:45:18
转载
541 人浏览过

适用于 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
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责声明 Sitemap
PHP中文网:公益在线PHP培训,帮助PHP学习者快速成长!