Work with DynamoDB
DynamoDB is a fully managed NoSQL database service that provides fast and predictable performance with seamless scalability. This section shows you how to work with DynamoDB using the Amazon SDK for Java 2.x.
Choose your DynamoDB client
The SDK provides two main approaches for working with DynamoDB:
- Low-level client (
DynamoDbClient
) -
Provides direct access to DynamoDB operations with full control over requests and responses. Use this client when you need fine-grained control or work with dynamic schemas.
- Enhanced client (
DynamoDbEnhancedClient
) -
Offers object-oriented programming with automatic mapping between Java objects and DynamoDB items. Also provides document-oriented capabilities for working with JSON-like data that doesn't follow a fixed schema. Use this client when working with well-defined data models or document-type data.
Configure DynamoDB clients
Before working with DynamoDB, configure your client for optimal performance and reliability.
Understand DynamoDB retry behavior
DynamoDB clients use a default maximum retry count of 8, which is higher than other Amazon Web Services service clients. This higher retry count helps handle DynamoDB's distributed nature and temporary capacity limitations. For more information about retry strategies, see Configure retry behavior in the Amazon SDK for Java 2.x.
Optimize performance with account-based endpoints
DynamoDB offers Amazon account-based endpoints that improve performance by using your Amazon account ID to streamline request routing.
To use this feature, you need version 2.28.4 or greater of the Amazon SDK for Java 2.x. You can
find the latest version in the Maven
central repository
To opt out of account-based routing, choose one of these options:
-
Configure a DynamoDB service client with
AccountIdEndpointMode
set toDISABLED
. -
Set an environment variable.
-
Set a JVM system property.
-
Update the shared Amazon config file setting.
The following example shows how to disable account-based routing by configuring a DynamoDB service client:
DynamoDbClient.builder() .accountIdEndpointMode(AccountIdEndpointMode.DISABLED) .build();
For more information about the other configuration options, see Account-based endpoints in the Amazon SDKs and Tools Reference Guide.
What's covered in this topic
The following sections show you how to work with DynamoDB:
-
Work with tables in DynamoDB - Create, describe, update, and delete tables
-
Work with items in DynamoDB - Add, retrieve, and update individual items
-
Map Java objects to DynamoDB items with the Amazon SDK for Java 2.x - Use object mapping and document-oriented data with the Enhanced Client
For additional DynamoDB code examples, see DynamoDB code examples in the Amazon Code Examples Library.