3

I'm trying to connect dynamodb with existing java project, but I found the error below:

com.amazonaws.SdkClientException: Unable to execute HTTP request: Connect to localhost:9000 [localhost/127.0.0.1, localhost/0:0:0:0:0:0:0:1] failed: Connection refused: connect

I have added below dependencies in pom.xml

       <dependency>
            <groupId>com.amazonaws</groupId>
            <artifactId>DynamoDBLocal</artifactId>
            <version>[1.11,2.0)</version>
        </dependency>
    <repositories>
        <repository>
            <id>dynamodb-local-oregon</id>
            <url>https://s3.eu-central-1.amazonaws.com/dynamodb-local-frankfurt/release</url>
        </repository>
    </repositories>

DynamoDBProxyServer server = ServerRunner.createServer(new CommandLineInput(new String[] {
                    "-dbPath",
                    System.getProperty("user.dir") + File.separator + "target", "-port", port
            }));
            server.start();
            AmazonDynamoDB dynamodb = AmazonDynamoDBClientBuilder.standard()
                    .withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration
                            ("http://localhost:" + port, "us-west-2"))
                    .withCredentials(new AWSStaticCredentialsProvider(new AWSCredentials() {
                        @Override
                        public String getAWSAccessKeyId() {
                            return "foo";
                        }

                        @Override
                        public String getAWSSecretKey() {
                            return "bar";
                        }
                    }))
                    .build();

DynamoDBMapper mapper = new DynamoDBMapper(dynamodb);
        CreateTableRequest req = mapper.generateCreateTableRequest(DocumentDescriptor.class);
        // Table provision throughput is still required since it cannot be specified in your POJO
        req.setProvisionedThroughput(new ProvisionedThroughput(5L, 5L));
        // Fire off the CreateTableRequest using the low-level client
        CreateTableResult result = dynamodb.createTable(req);
        System.out.println(result.toString());

When it executes CreateTableResult result = dynamodb.createTable(req);, it gives me connection refused error.

Please help me out. Thanks in advance.

Prince Vegeta
  • 719
  • 6
  • 21
rubal garg
  • 31
  • 3

0 Answers0