Using the Gremlin Console to Connect to a Neptune DB Instance
The Gremlin Console allows you to experiment with TinkerPop graphs and queries in a REPL (read-eval-print loop) environment.
You can use the Gremlin Console to connect to a remote graph database. The following section walks you through the configuration of the Gremlin Console to connect remotely to a Neptune DB instance. You must follow these instructions from an Amazon EC2 instance in the same virtual private cloud (VPC) as your Neptune DB instance.
To connect to Neptune using the Gremlin Console
-
The Gremlin Console binaries require Java 8. Enter the following to install Java 8 on your EC2 instance.
sudo yum install java-1.8.0-devel
-
Enter the following to set Java 8 as the default runtime on your EC2 instance.
sudo /usr/sbin/alternatives --config java
When prompted, enter the number for Java 8.
-
Download Gremlin Console (version 3.3.2+) from the Apache Tinkerpop3 website on to your EC2 instance.
wget https://archive.apache.org/dist/tinkerpop/3.3.2/apache-tinkerpop-gremlin-console-3.3.2-bin.zip
-
Unzip the Gremlin Console zip file.
unzip apache-tinkerpop-gremlin-console-3.3.2-bin.zip
-
Change directories into the unzipped directory.
cd apache-tinkerpop-gremlin-console-3.3.2
-
Download the CA certificate. Gremlin Console requires a certificate to verify the remote certificate.
wget https://www.amazontrust.com/repository/SFSRootCAG2.pem
-
In the
conf
subdirectory of the extracted directory, create a file namedneptune-remote.yaml
with the following text. Replaceyour-neptune-endpoint
with the hostname or IP address of your Neptune DB instance. The square brackets ([ ]
) are required.Note
For information about finding the hostname of your Neptune DB instance, see the Connecting to Amazon Neptune Endpoints section.
hosts: [
your-neptune-endpoint
] port: 8182 connectionPool: { enableSsl: true, trustCertChainFile: "SFSRootCAG2.pem"} serializer: { className: org.apache.tinkerpop.gremlin.driver.ser.GryoMessageSerializerV3d0, config: { serializeResultToString: true }} -
In a terminal, navigate to the Gremlin Console directory (
apache-tinkerpop-gremlin-console-3.3.2
), and then enter the following command to run the Gremlin Console.bin/gremlin.sh
You should see the following output:
\,,,/ (o o) -----oOOo-(3)-oOOo----- plugin activated: tinkerpop.server plugin activated: tinkerpop.utilities plugin activated: tinkerpop.tinkergraph gremlin>
You are now at the
gremlin>
prompt. You will enter the remaining steps at this prompt. -
At the
gremlin>
prompt, enter the following to connect to the Neptune DB instance.:remote connect tinkerpop.server conf/neptune-remote.yaml
-
At the
gremlin>
prompt, enter the following to switch to remote mode. This sends all Gremlin queries to the remote connection.:remote console
-
Enter the following to send a query to the Gremlin Graph.
g.V().limit(1)
-
When you are finished, enter the following to exit the Gremlin Console.
:exit
Note
Use a semicolon (;
) or a newline character (\n
) to separate
each statement.
Each traversal preceding the final traversal must end in next()
to be
executed. Only the data from the final traversal is returned.
For more information on the Neptune implementation of Gremlin, see Neptune Gremlin Implementation Differences.
For more information about Amazon Neptune, see Next Steps.