Home  >  Article  >  Backend Development  >  Golang SDK for Dynamodb: ReturnValuesOnConditionCheckFailure does not return details about the condition when the condition chcekfailure occurs

Golang SDK for Dynamodb: ReturnValuesOnConditionCheckFailure does not return details about the condition when the condition chcekfailure occurs

PHPz
PHPzforward
2024-02-10 18:45:18541browse

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

php editor Xiaoxin introduces to you an important feature in the Golang SDK for Dynamodb: ReturnValuesOnConditionCheckFailure. This feature protects sensitive data by not returning detailed information about the condition if the condition check fails. Using this feature, developers can handle condition check failures more safely and improve application reliability. In this article, we will delve into the usage and advantages of this feature to help developers better understand and apply it to actual projects.

Question content

I am using golang sdk https://pkg.go.dev/github.com/aws/[email protected]/ to check debugging conditions error and find information about why a single write operation failed, but I can only see the error Message_: "Conditional request failed". No additional information about the specific cause is provided when using the parameter ReturnValuesOnConditionCheckFailure: ALL_OLD in UpdateItemInput. For TransactWriteItems, I can see exactly why the condition check failed when using the same parameters. How can I get these details for a single write operation? Reference: https://aws.amazon.com/about-aws/whats-new/2023/06/amazon-dynamodb-cost-failed-conditional-writes Syntax I am using:

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)

Solution

The item should be located inside the error component, usually in error.response.Item.

For example in 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")

Note: If you are using DynamoDB Local, this feature does not exist yet

The above is the detailed content of Golang SDK for Dynamodb: ReturnValuesOnConditionCheckFailure does not return details about the condition when the condition chcekfailure occurs. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:stackoverflow.com. If there is any infringement, please contact admin@php.cn delete