How can I visualize a Gremlin graph from Amazon Neptune with Graphexp?

Last updated: 2020-02-05

I want to use Graphexp to visualize a Gremlin graph that's stored in Amazon Neptune.

Resolution

Prerequisites

1.    Create a Neptune DB cluster.

2.    Create an Amazon Elastic Compute Cloud (Amazon EC2) Linux instance in the same virtual private cloud (VPC) as the Neptune cluster. Be sure that the instance is accessible from your local computer through an SSH connection.

3.    Create a VPC security group that allows the EC2 instance to connect to the Neptune cluster from within the VPC. For more information, see Accessing Neptune DB Clusters in an Amazon VPC.

4.    On the EC2 instance, install the Gremlin Console and connect to Neptune.

Load the Gremlin graph

Note: The following examples use the property graph from the Apache TinkerPop GitHub documentation.

In the Gremlin Console:

1.    Add vertices:

g.addV('person').property(id,'v1').property('name','marko').property('age','29').
  addV('person').property(id,'v2').property('name','vadas').property('age','27').
  addV('software').property(id,'v3').property('name','lop').property('lang','java').
  addV('person').property(id,'v4').property('name','josh').property('age','32').
  addV('software').property(id,'v5').property('name','ripple').property('lang','java').
  addV('person').property(id,'v6').property('name','peter').property('age','35')

2.    Add edges:

g.addE('created').from(g.V('v1')).to(g.V('v3')).property(id,'e9').property('weight','0.4')
g.addE('created').from(g.V('v4')).to(g.V('v5')).property(id,'e10').property('weight','1.0')
g.addE('created').from(g.V('v4')).to(g.V('v3')).property(id,'e11').property('weight','0.4')
g.addE('created').from(g.V('v6')).to(g.V('v3')).property(id,'e12').property('weight','0.2')
g.addE('knows').from(g.V('v1')).to(g.V('v2')).property(id,'e7').property('weight','0.4')
g.addE('knows').from(g.V('v1')).to(g.V('v4')).property(id,'e8').property('weight','1.0')

Set up the SSH tunnel

The SSH tunnel allows your local computer to connect to the EC2 server and then connect to the Neptune instance using local port forwarding. You can create the SSH tunnel using an SSH client or PuTTY.

To connect with an SSH client, run the following command. The example uses these values:

8182: the port for the Neptune cluster
mydbcluster.cluster-123456789012.eu-west-1.neptune.amazonaws.com: the Neptune cluster endpoint
my_keypair.pem: your private key pair file
ec2-user@ec2-11-111-11-111.eu-west-1.compute.amazonaws.com: the public DNS hostname of the EC2 instance

ssh -L 8182:mydbcluster.cluster-123456789012.eu-west-1.neptune.amazonaws.com:8182 -i my_keypair.pem ec2-user@ec2-11-111-11-111.eu-west-1.compute.amazonaws.com

PuTTY:

1.    In the Category pane, choose Session and then complete the following fields: For Host Name, enter the public DNS hostname of the EC2 instance. For Port, be sure that the value is 22.

2.    In the Category list, expand Connection > SSH, and then choose Tunnels. Complete the following: For Source port, enter the port that you chose when you created the Neptune cluster, such as 8182. For Destination, enter the Neptune cluster endpoint and port. Example: mydbcluster.cluster-123456789012.eu-west-1.neptune.amazonaws.com:8182. Select the Local and Auto options.

3.    Choose Add, and then choose Open. When the session opens, an event log appears:

[timestamp] Local port 8182 forwarding to mydbcluster.cluster-123456789012.eu-west-1.neptune.amazonaws.com:8182

Set up Graphexp

1.    Download the Graphexp package from GitHub.

2.    Extract the zip file on your local file system.

3.    Open the scripts/graphConf.js file and set the following parameters:

const host = "localhost";
const SINGLE_COMMANDS_AND_NO_VARS = true

Access the Neptune graph in your browser

1.    In your browser, enter the path to the graphexp.html file in the unzipped Graphexp directory. Example: file:///C:/Neptune/graphexp-master/graphexp-master/graphexp.html.

2.    Choose Get graph info and then choose Search to load and display the Gremlin graph.


Did this article help you?

Anything we could improve?


Need more help?