DynamoDbEnhancedClient (AWS SDK for Java

Puts and/or deletes multiple items in one or more tables. BatchWriteItem is a composite operation where the request contains one batch of (a mix of) PutItemEnhancedRequest and DeleteItemEnhancedRequest per targeted table.

The additional configuration parameters that the enhanced client supports are defined in the BatchWriteItemEnhancedRequest.

A single call to BatchWriteItem has the same limit of items as the low-level DynamoDB API BatchWriteItem operation, considering all items across all WriteBatches.

Note: BatchWriteItem cannot update items. Instead, use the individual updateItem operation DynamoDbTable.updateItem(UpdateItemEnhancedRequest).

Partial updates
Each delete or put call is atomic, but the operation as a whole is not. If individual operations fail due to exceeded provisional throughput internal DynamoDb processing failures, the failed requests can be retrieved through the result, see BatchWriteResult.

There are some conditions that cause the whole batch operation to fail. These include non-existing tables, erroneously defined primary key attributes, attempting to put and delete the same item as well as referring more than once to the same hash and range (sort) key.

This operation calls the low-level DynamoDB API BatchWriteItem operation. Consult the BatchWriteItem documentation for further details and constraints, current limits of data to write and/or delete, how to handle partial updates and retries and under which conditions the operation will fail.

Note: This is a convenience method that creates an instance of the request builder avoiding the need to create one manually via BatchWriteItemEnhancedRequest.builder().

Example:

  BatchWriteResult batchResult = enhancedClient.batchWriteItem(r -> r.writeBatches( WriteBatch.builder(FirstItem.class) .mappedTableResource(firstItemTable) .addPutItem(i -> i.item(item1)) .addDeleteItem(i -> i.key(key2)) .build(), WriteBatch.builder(SecondItem.class) .mappedTableResource(secondItemTable) .addPutItem(i -> i.item(item3)) .build()));  

You Might Also Like