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 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…