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

PHPz
Release: 2024-02-10 18:45:18
forward
543 people have browsed it

适用于 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)
Copy after login

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")
Copy after login

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!

Related labels:
source:stackoverflow.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!