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

3 minute read
0

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

Short description

To use Graphexp to visualize a Gremlin graph, complete the following 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.    Confirm that your AWS Identity and Access Management (IAM) authentication is disabled.

5.    On the EC2 instance, install the Gremlin console and connect to Neptune.

Note: If the neptune_enforce_ssl parameter is set to "true" for your database, then use an HTTPS (wss) connection. Or if you use REST over HTTPS, set your REST_USE_HTTPS parameter to "true". Otherwise, you receive a connection error. For more information, see Encryption in transit: Connecting to Neptune using SSL/HTTPS.

Resolution

Load the Gremlin graph

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

In the Gremlin console, perform the following steps:

1.    Add the 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 the 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 using 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 fields:
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. For example:

file:///C:/Neptune/graphexp-main/graphexp-main/graphexp.html

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


Related information

Accessing the Neptune graph with Gremlin

Using Gremlin to access the graph

AWS OFFICIAL
AWS OFFICIALUpdated 3 years ago