用Java拒绝Dynamodb本地连接

时间:2019-07-17 06:10:36

标签: java amazon-dynamodb aws-sdk amazon-dynamodb-local

我正在尝试将dynamodb与现有的Java项目连接,但发现以下错误:

  

com.amazonaws.SdkClientException:无法执行HTTP请求:   连接到localhost:9000 [localhost / 127.0.0.1,   本地主机/ 0:0:0:0:0:0:0:0:1]失败:连接被拒绝:连接

我在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());

执行CreateTableResult result = dynamodb.createTable(req);时会给我connection refused error

请帮帮我。预先感谢。

0 个答案:

没有答案