首頁 > 後端開發 > 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學習者快速成長!