具有返回值参数的 DynamoDB 更新项不会在失败的条件表达式上返回任何内容


Using aws

/aws-sdk-php 3.21.6.我一定误解了当条件表达式满足条件检查失败异常错误时 ReturnValues 是如何工作的。

我希望的是,如果 ConditionExpression 失败,进而触发 ConditionalCheckFailedException,我可以捕获此异常,然后通过 ReturnValues 从 DD 访问新属性。

我期望从 ReturnValue 获得的文档属性似乎暗示了这一点。

但是,从测试中,ReturnValues 仅在条件表达式为 true 时才返回属性,而不是在失败时返回属性。

$response = $client->updateItem([
    'TableName' => 'MyTable',
    'Key' => [
        'customer_url' => [
            'S' => 'someurl.com'
        ],
        'customer_platform' => [
            'S' => 'some_platform'
        ]
    ],
    'ExpressionAttributeNames' => [
        '#C' => 'createdAt'
    ],
    'ExpressionAttributeValues' =>  [
        ':val1' => [
            'S' => '2017-01-24T14:15:32'
        ],
        ':val2' => [
            'S' => '2017-01-24T14:15:30'
        ]
    ],
    'UpdateExpression' => 'set #C = :val1',
    'ConditionExpression' => '#C = :val2', // :val2 originally was 2017-01-24T14:15:30, before attempting to update to 2017-01-24T14:15:32. If I change the field to 2017-01-24T14:15:31, before running this update it will throw the ConditionalCheckFailedException
    'ReturnValues' => 'ALL_NEW'
]);
是的

,仅当updateItem成功时,才会填充ReturnValues。如果由于ConditionalCheckFailedException或任何其他原因而失败,则ReturnValues将为 null。

支持文档来自这里,重点是我的:

如果要获取更新之前或之后显示的项属性,请使用 ReturnValues。