Jackie
Jackie

Reputation: 23509

How do I connect to Neptune using Java

I have the following code based on the docs...

@Controller
@RequestMapping("neptune")
public class NeptuneEndpoint {
    @GetMapping("")
    @ResponseBody
    public String test(){
        Cluster.Builder builder = Cluster.build();
        builder.addContactPoint("...endpoint...");
        builder.port(8182);

        Cluster cluster = builder.create();

        GraphTraversalSource g = EmptyGraph.instance()
                                           .traversal()
                                           .withRemote(
                                               DriverRemoteConnection.using(cluster)
                                           );

        GraphTraversal t = g.V().limit(2).valueMap();

        t.forEachRemaining(
                e ->  System.out.println(e)
        );

        cluster.close();
        return "Neptune Up";
    }
}

But when I try to run I get ...

java.util.concurrent.TimeoutException: Timed out while waiting for an available host - check the client configuration and connectivity to the server if this message persists

Also how would I add Secret key from AWS IAM account?

Upvotes: 3

Views: 2547

Answers (5)

HIMANSHU GOYAL
HIMANSHU GOYAL

Reputation: 481

Refer this

Note: You need to be in the same VPC to access Neptune cluster.

Upvotes: -1

monken
monken

Reputation: 146

Another option is to use a AWS SigV4 signing proxy that acts as a bridge between Neptune and your local development environment. One of these proxies is https://github.com/monken/aws4-proxy

npm install --global aws4-proxy
# have your credentials exported as AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY
aws4-proxy --service neptune-db --endpoint cluster-die4eenu.cluster-eede5pho.eu-west-1.neptune.amazonaws.com --region eu-west-1
wscat localhost:3000/gremlin

Upvotes: 0

Priyank Agrawal
Priyank Agrawal

Reputation: 280

Neptune doesn't allow you to connect to the db instance from your local machine. You can only connect to Neptune via an EC2 inside the same VPC as Neptune (aws documentation).

Try making a runnable jar of this code and run it inside an ec2, the code should work fine. If you're trying to debug something from your local system, then use PuTTY instance tunneling to connect to ec2 which then will be forwarded to neptune cluster.

Upvotes: 4

shooit
shooit

Reputation: 11

I just had the same issue and the root cause was a dependency version conflict with Netty which is unfortunately a very pervasive dependency. Gremlin 3.3.2 uses io.netty/netty-all version 4.0.56.Final. You might find your project depends on another Netty jar such as io.netty/netty or io.netty/netty-handler both of which can cause issues so you will need to excluded them from other dependencies in your POM or use managed-dependencies to set a project level Netty version.

Upvotes: 1

Divij Vaidya
Divij Vaidya

Reputation: 261

Have you created an instance with IAM auth enabled?

If yes, you will have to sign your request using SigV4. More information (and examples) on how to connect using SigV4 is available at https://docs.aws.amazon.com/neptune/latest/userguide/iam-auth-connecting-gremlin-java.html

The examples given in the documentation above also contain information on how to use your IAM credentials to connect to a Neptune cluster.

Upvotes: 2

Related Questions