Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.8k views
in Technique[技术] by (71.8m points)

amazon dynamodb - Dynamo DB Local - Connection Refused

I am trying to connect to Local Dynamo DB using the AWS Java SDK. So I installed the Local Dynamo DB and started the javascript shell. All works fine and the shell starts at the usual address http://localhost:8000/shell/

Now when I try to access the Dynamo DB Instance via the AWS SDK things start to break.

Here is my code:

public class MyDynamoDB {
    private AmazonDynamoDBClient client;

    public MyDynamoDB() {
        client = new AmazonDynamoDBClient();
        client.setEndpoint("http://localhost:8000");
    }

    public void saveAndLoad() {
        DynamoDBMapperConfig config = new DynamoDBMapperConfig(new TableNameOverride("xyz"));
        DynamoDBMapper mapper = new DynamoDBMapper(client, config);
        Data data = new Data();
        ...
        mapper.save(data);


        //check if persisted
        Data d = mapper.load(Data.class, "Key");
        if (d != null) {
            System.out.println(" Found data: " + d.getStuff());
        } else {
            System.out.println("Data not found");
        }
    }
}

On running this I am getting the following stack trace

Nov 19, 2015 4:00:47 PM com.amazonaws.http.AmazonHttpClient executeHelper
INFO: Unable to execute HTTP request: Connection refused: connect
java.net.ConnectException: Connection refused: connect
at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at org.apache.http.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.java:117)
at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:177)
at org.apache.http.impl.conn.ManagedClientConnectionImpl.open(ManagedClientConnectionImpl.java:304)
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You need to trigger DynamoDB in command prompt..

Go the location where the Dynamodb cli is installed and run the following command

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

verify if it is running by http://localhost:8000/shell/


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...