
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中:
立即学习“go语言免费学习笔记(深入)”;
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中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号