Tien Vu
Tien Vu

Reputation: 97

How to connect to Amazon Neptune by using ssh Java

I've setup a ssh tunnel to allow connecting to NeptuneDB and now i want to use Java from local machine to connect to NeptuneDB by using ssh, so is there any way to do that?

Upvotes: 0

Views: 364

Answers (1)

Kelvin Lawrence
Kelvin Lawrence

Reputation: 14371

Yes it’s possible. You need to add the DNS name of the Neptune cluster to your local hosts file and use that name in your code and when creating the SSH tunnel. Do not use localhost as the SSL certs will not resolve if you do. The line in your hosts file will be of the form:

127.0.0.1 localhost my.cluster-abcdefghijk.us-east-1.neptune.amazonaws.com

The ssh tunnel can then be created using something like

ssh -i mypem.pem [email protected]  -N -L 8182:my.cluster-abcdefghijk.us-east-1.neptune.amazonaws.com:8182

In your Java code you can then build the connection something like this:

Cluster.Builder builder = Cluster.build();
builder.addContactPoint("my.cluster-abcdefghijk.us-east-1.neptune.amazonaws.com");
builder.port(8182);
builder.serializer(Serializers.GRAPHBINARY_V1D0);
builder.enableSsl(true);
cluster = builder.create();
drc = DriverRemoteConnection.using(cluster);
g = traversal().withRemote(drc);

Upvotes: 1

Related Questions