Are transaction cancellation reasons returned in the same order as the TransactWriteItemsRequest

Viewed 210

We are using the DynamoDB transaction API to perform 2 writes:

  TransactWriteItemsRequest transactionalWriteRequest = new TransactWriteItemsRequest();
  transactionalWriteRequest.withTransactItems(writeOne, writeTwo); 
  dynamoDB.transactWriteItems(transactionalWriteRequest);

If the transaction fails with a TransactionCanceledException we get back an exception with a list of CancellationReason objects.

In my scenario, imagine writeOne and writeTwo both fail. The exception will return two cancellation reasons.

My question is - does the ordering of those reasons match the ordering of the transactions in my request.

Is this always true?

 // Explains why writeOne failed
 transactionError.getCancellationReasons().get(0);
 // Explains why writeTwo failed
 transactionError.getCancellationReasons().get(1);

Thanks

1 Answers

According to the docs - yes, the ordering of cancellation reasons matches the order of transaction items: https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_TransactWriteItems.html

If using Java, DynamoDB lists the cancellation reasons on the CancellationReasons property. This property is not set for other languages. Transaction cancellation reasons are ordered in the order of requested items, if an item has no error it will have NONE code and Null message.

Related