Select your cookie preferences

We use essential cookies and similar tools that are necessary to provide our site and services. We use performance cookies to collect anonymous statistics, so we can understand how customers use our site and make improvements. Essential cookies cannot be deactivated, but you can choose “Customize” or “Decline” to decline performance cookies.

If you agree, AWS and approved third parties will also use cookies to provide useful site features, remember your preferences, and display relevant content, including relevant advertising. To accept or decline all non-essential cookies, choose “Accept” or “Decline.” To make more detailed choices, choose “Customize.”

Use the DynamoDB Enhanced Client API asynchronously - AWS SDK for Java 2.x

Use the DynamoDB Enhanced Client API asynchronously

If your application requires non-blocking, asynchronous calls to DynamoDB, you can use the DynamoDbEnhancedAsyncClient. It's similar to the synchronous implementation but with the following key differences:

  1. When you build the DynamoDbEnhancedAsyncClient, you must provide the asynchronous version of the standard client, DynamoDbAsyncClient, as shown in the following snippet.

    DynamoDbEnhancedAsyncClient enhancedClient = DynamoDbEnhancedAsyncClient.builder() .dynamoDbClient(dynamoDbAsyncClient) .build();
  2. Methods that return a single data object return a CompletableFuture of the result instead of only the result. Your application can then do other work without having to block on the result. The following snippet shows the asynchronous getItem() method.

    CompletableFuture<Customer> result = customerDynamoDbTable.getItem(customer); // Perform other work here. return result.join(); // Now block and wait for the result.
  3. Methods that return paginated lists of results return an SdkPublisher instead of an SdkIterable that the synchronous DynamoDbEnhanceClient returns for the same methods. Your application can then subscribe a handler to that publisher to deal with the results asynchronously without having to block.

    PagePublisher<Customer> results = customerDynamoDbTable.query(r -> r.queryConditional(keyEqualTo(k -> k.partitionValue("Smith")))); results.subscribe(myCustomerResultsProcessor); // Perform other work and let the processor handle the results asynchronously.

    For a more complete example of working with the SdkPublisher API, see the example in the section that discusses the asynchronous scan() method of this guide.

PrivacySite termsCookie preferences
© 2025, Amazon Web Services, Inc. or its affiliates. All rights reserved.