Search code examples
amazon-dynamodbaws-java-sdk-2.x

DynamoDB java sdk v2 client batchWrite retries


Does the DynamoDB Java SDKv2 offer a retry strategy for batchWriteItem calls? I'm looking for a retry strategy that retries items that would otherwise be returned as unprocessedItems.

In the DynamoDB Java SDKv1 there was the DynamoDBMapper default retry strategy to achieve this, see https://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/services/dynamodbv2/datamodeling/DynamoDBMapperConfig.DefaultBatchWriteRetryStrategy.html.

I couldn't find anything related to retries out of the box for batch operations in the official javadoc, e.g. https://sdk.amazonaws.com/java/api/latest/software/amazon/awssdk/services/dynamodb/DynamoDbClient.html#batchWriteItem(java.util.function.Consumer) or https://sdk.amazonaws.com/java/api/latest/software/amazon/awssdk/enhanced/dynamodb/package-summary.html.

I was hoping I don't have to implement retries myself on top of the default or enhanced client.


Solution

  • Just ran into this issue a few days ago.

    The document suggests a simple loop way now instead of complex retry strategy. And the loop code is simple :)

    Document link:

    Typically, you would call BatchWriteItem in a loop. Each iteration would check for unprocessed items and submit a new BatchWriteItem request with those unprocessed items until all items have been processed.

    And aws also provides code example here