Inefficient usage of Transaction library from AWS Labs Low

DynamoDB transactional APIs provide native, server-side transactions. The AWS Labs Transactions Library is a client-side solution. DynamoDB native transactions are more cost effective and provide better application performance.

Detector ID
java/dynamodb-transaction-library@v1.0
Category

Noncompliant example

1import com.amazonaws.services.dynamodbv2.transactions.TransactionManager;
2
3public class DynamodbTransactionLibraryNoncompliant {
4    public void createTransactionNoncompliant() throws Exception {
5        // Noncompliant: uses AWS Lab Transactions Library over DynamoDB native transactional APIs.
6        TransactionManager.verifyOrCreateTransactionTable("client", "Transactions", 1, 1, null);
7    }
8}

Compliant example

1public class DynamodbTransactionLibraryCompliant {
2    public void DynamoDBTransactionLibraryCompliant(String name) throws InterruptedException {
3        final Map<String, AttributeValue> item = createItem();
4        final Put put = new Put()
5                .withTableName(name)
6                .withItem(item);
7        // Compliant: uses DynamoDB native transactional APIs over AWS Lab Transactions Library.
8        final TransactWriteItem transactWriteItem = new TransactWriteItem().withPut(put);
9        final TransactWriteItemsRequest request = new TransactWriteItemsRequest()
10                .withTransactItems(transactWriteItem)
11                .withReturnConsumedCapacity("TOTAL");
12    }
13
14    private Map<String, AttributeValue> createItem() {
15        Map<String, AttributeValue> item = Collections.emptyMap();
16        return item;
17    }
18}