0

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?

Kelvin Lawrence
  • 14,674
  • 2
  • 16
  • 38
Tien Vu
  • 87
  • 7
  • This question comes up quite often and makes perfect sense to me. I have provided a detailed answer below. However, to avoid a moderator closing this question it would be good if you can add a little more information about what you had already tried per Stack Overflow guidelines. – Kelvin Lawrence Oct 21 '21 at 14:06

1 Answers1

1

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 ec2-user@ec2-xx-xx-xx-xx.compute-1.amazonaws.com  -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);
Kelvin Lawrence
  • 14,674
  • 2
  • 16
  • 38
  • Thanks, your code worked but i want to use spring boot to get data from neptune database. Do you have any config ? i use intelliJ IDE to code, so what do i have to add for app.properties file? – Tien Vu Oct 26 '21 at 06:47
  • I’m glad the code worked. However, That’s really a new question. Perhaps accept the answer to this one and create a new question for Spring Boot so that people expert in that area will see it? – Kelvin Lawrence Oct 26 '21 at 12:00