0

I am creating an inMemory dynamoDB locally with com.amazonaws' dynamodblocal (v 1.10.5.1 from maven).

Java code to start the local server is:

server = ServerRunner.createServerFromCommandLineArgs({ "port", getAvailablePort(), "-inMemory", "-sharedDb" });
server.start();
AmazonDynamoDBClient amazonDynamoDBClient = new AmazonDynamoDBClient(basicAWSCredentials);

Here is the log confirming I have successfully started a local dynamodb:

Initializing DynamoDB Local with the following configuration:
Port:   60677
InMemory:   true
DbPath: null
SharedDb:   true
shouldDelayTransientStatuses:   false
CorsParams: *

Port 60677 is used here and I can manually open up http://localhost:60677/shell from a web browser. But it doesn't work when I try to reach it programmatically. I keep getting HTTP/1.1 500 Server Error.

This would give me 500 Error (port would be the output of getAvailablePort()):

amazonDynamoDBClient.setEndpoint("http://localhost:" + port);
amazonDynamoDBClient.listTables();

Also when I start one from the command line with:

java -Djava.library.path=./DynamoDBLocal_lib -jar DynamoDBLocal.jar -port 9999 -inMemory -sharedDb

and try to connect to it programmatically, it works fine. It allows me do all CRUD operations programmatically.

What am I doing wrong?

danksim
  • 617
  • 3
  • 9
  • 27

1 Answers1

1

When the local DynamoDB server is up and running, you can use the below code to get the list of tables.

Just change the port number accordingly in the below code. The basicAWSCredentials is not required.

DynamoDB dynamoDB = new DynamoDB(new AmazonDynamoDBClient().withEndpoint("http://localhost:8000"));

TableCollection<ListTablesResult> tables = dynamoDB.listTables();
Iterator<Table> iterator = tables.iterator();

while (iterator.hasNext()) {
    Table table = iterator.next();
    System.out.println(table.getTableName());
}
notionquest
  • 37,595
  • 6
  • 111
  • 105