Changes in Waiters from version 1 to version 2 - Amazon SDK for Java 2.x
Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with Amazon Web Services in China (PDF).

Changes in Waiters from version 1 to version 2

This topic details the changes in the functionality of Waiters from version 1 (v1) to version 2 (v2).

The following tables demonstrate the difference for DynamoDB waiters specifically. Waiters for other services follow the same pattern.

High-level changes

Waiters classes are in the same Maven artifact as the service.

Change v1 v2

Maven dependencies

<dependencyManagement> <dependencies> <dependency> <groupId>com.amazonaws</groupId> <artifactId>aws-java-sdk-bom</artifactId> <version>1.12.6801</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> <dependencies> <dependency> <groupId>com.amazonaws</groupId> <artifactId>dynamodb</artifactId> </dependency> </dependencies>
<dependencyManagement> <dependencies> <dependency> <groupId>software.amazon.awssdk</groupId> <artifactId>bom</artifactId> <version>2.27.102</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> <dependencies> <dependency> <groupId>software.amazon.awssdk</groupId> <artifactId>dynamodb</artifactId> </dependency> </dependencies>
Package name com.amazonaws.services.dynamodbv2.waiters software.amazon.awssdk.services.dynamodb.waiters
Class names

AmazonDynamoDBWaiters

1 Latest version. 2 Latest version.

API changes

Change v1 v2
Create a waiter
AmazonDynamoDB client = AmazonDynamoDBClientBuilder .standard().build(); AmazonDynamoDBWaiters waiter = client.waiters();
Synchronous:
DynamoDbClient client = DynamoDbClient.create(); DynamoDbWaiter waiter = client.waiter();

Asynchronous:

DynamoDbAsyncClient asyncClient = DynamoDbAsyncClient.create(); DynamoDbAsyncWaiter waiter = asyncClient.waiter();
Wait until a table exists Synchronous:
waiter.tableExists() .run(new WaiterParameters<>( new DescribeTableRequest(tableName)));

Asynchronous:

waiter.tableExists() .runAsync(new WaiterParameters() .withRequest(new DescribeTableRequest(tableName)), new WaiterHandler() { @Override public void onWaitSuccess( AmazonWebServiceRequest amazonWebServiceRequest) { System.out.println("Table creation succeeded"); } @Override public void onWaitFailure(Exception e) { e.printStackTrace(); } }).get();

Synchronous:

WaiterResponse<DescribeTableResponse> waiterResponse = waiter.waitUntilTableExists( r -> r.tableName("myTable")); waiterResponse.matched().response() .ifPresent(System.out::println);

Asynchronous:

waiter.waitUntilTableExists(r -> r.tableName(tableName)) .whenComplete((r, t) -> { if (t != null) { t.printStackTrace(); } else { System.out.println( "Table creation succeeded"); } }).join();

Configuration changes

Change v1 v2
Polling Strategy (max attempts and fixed delay)
MaxAttemptsRetryStrategy maxAttemptsRetryStrategy = new MaxAttemptsRetryStrategy(10); FixedDelayStrategy fixedDelayStrategy = new FixedDelayStrategy(3); PollingStrategy pollingStrategy = new PollingStrategy(maxAttemptsRetryStrategy, fixedDelayStrategy); waiter.tableExists().run( new WaiterParameters<>( new DescribeTableRequest(tableName)), pollingStrategy);
FixedDelayBackoffStrategy fixedDelayBackoffStrategy = FixedDelayBackoffStrategy .create(Duration.ofSeconds(3)); waiter.waitUntilTableExists(r -> r.tableName(tableName), c -> c.maxAttempts(10) .backoffStrategy(fixedDelayBackoffStrategy));