How to configure the endpoint in a local instance of dynamodb java aws sdk 2.x?

Viewed 2505

I am very new to DynamoDB and started learning with the Java AWS SDK 1.x. I initialized my local dynamodb endpoint with the following code

AmazonDynamoDB client = AmazonDynamoDBClientBuilder
                       .standard()
                       .withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration("http://localhost:8000","us-west-2"))
                       .build();

DynamoDB dynamoDB = new DynamoDB(client);

However now I changed my dependencies to Dynamodb and Java 2.15.52, so the client is initialized as:

DynamoDbClient client = DynamoDbClient.builder().build();

How can I configure my local endpoint with the new DynamoDbClient?

1 Answers

The translation to the new version in order to initialize the client of your example would be as follows:

DynamoDbClient client = DynamoDbClient.builder()
                        .region(Region.US_WEST_2)
                        .endpointOverride(URI.create("http://localhost:8000"))
                        .build();

DynamoDB dynamoDB = new DynamoDB(client);

endpointOverride() is inherited from SdkClientBuilder

endpointOverride(URI endpointOverride)

Configure the endpoint with which the SDK should communicate.`

region() is inherited from AwsClientBuilder

region(Region region)

Configure the region with which the SDK should communicate.


More info about upgrading the DynamoDB client here.

Related