TransactWriteItems Java:如何使用ReturnValuesOnConditionCheckFailure获得响应

时间:2019-07-18 22:43:10

标签: amazon-dynamodb

我正在使用DynamoDB TransactWriteItems API,并且文档说,当条件检查失败时,我们可以使用ReturnValuesOnConditionCheckFailure字段获取项目属性。我通过将ReturnValuesOnConditionCheckFailure设置为ALL_OLD进行了TransactWriteItems调用:

try {
    client.transactWriteItems(placeOrderTransaction);
    System.out.println("Transaction Successful");
    } catch (TransactionCanceledException tce) {
    System.out.println("Transaction Canceled " + tce.getMessage());
}

但是在控制台中,我只会看到:

Transaction Canceled Transaction cancelled, please refer cancellation reasons for specific reasons [ConditionalCheckFailed, None, ConditionalCheckFailed] (Service: AmazonDynamoDBv2; Status Code: 400; Error Code: TransactionCanceledException; Request ID: b25d2b81-38d7-4c83-a17f-52ca4b71ec21)

我在哪里可以获得商品属性?

1 个答案:

答案 0 :(得分:0)

您可以通过以下代码获取项目。但是项目地图是空白的,我不确定如何在取消原因中启用 AWS 服务来发送项目。

List<CancellationReason> reasons = e.cancellationReasons();
        reasons.forEach(reason -> {
            reason.item();
        });