Cannot access Neptune using bolt with neo4j cypher or wss gremlin

0

I have an AWS Neptune cluster, however cannot access it for loading or reading data.

I am able to access the cluster using curl, so I can confirm connection, however when trying to use neo4j or gremlin python library, it ends up failing to connect.

These work:

curl -vG <endpoint>:8182/openCypher -d "query=CREATE (n:Person { age: 25 })"
curl -X POST -d '{"gremlin":"g.V().limit(1)"}' <endpoint>:8182/gremlin

For reference, my cluster has IAM condition disabled.

OpenCypher Repro fails due to connection:

from neo4j import GraphDatabase
uri = "bolt://(your cluster endpoint URL):(your cluster port)"
driver = GraphDatabase.driver(uri, encrypted=True)

def match_person_nodes(tx, name_filter):
    result = tx.run("""
        MATCH (p:Person) WHERE p.name STARTS WITH $filter
        RETURN p.name AS name ORDER BY name
        """, filter=name_filter)
    return list(result)  # return a list of Record objects

with driver.session() as session:
    people = session.execute_read(
        match_person_nodes,
        "Al",
    )
    for person in people:
        print(person.data())

Gremlin Repro just ends up hanging:

remoteConn = DriverRemoteConnection(writer_url, "g")
g = traversal().withRemote(remoteConn)
print(g.inject(1).toList())
remoteConn.close()
  • Are your curl commands and your Python scripts being run from the same source location? Both are executed with access to the Neptune endpoint?

asked a month ago75 views
1 Answer
-2

It appears you're encountering issues connecting to your Neptune cluster using both the Bolt protocol for openCypher and WebSocket for Gremlin. Let's address each of these separately.

For the openCypher connection using Bolt: The issue likely stems from how you're trying to connect. Neptune requires a specific configuration when using Bolt. Instead of using "bolt://" in your connection string, you should use "bolt+s://" to ensure an encrypted connection. Also, you need to set up the driver with the correct authentication and trust strategy. Here's how you can modify your code:

from neo4j import GraphDatabase, Auth
uri = "bolt+s://(your cluster endpoint URL):8182"
driver = GraphDatabase.driver(uri, auth=Auth.NONE, encrypted=True, trust="TRUST_ALL_CERTIFICATES")

For the Gremlin connection: The hanging issue might be related to how you're setting up the connection. Make sure you're using the WebSocket secure (wss) protocol and the correct port. Here's an example of how to set up the connection:

from gremlin_python.driver.driver_remote_connection import DriverRemoteConnection
from gremlin_python.structure.graph import Graph
from gremlin_python.process.anonymous_traversal import traversal

writer_url = 'wss://(your cluster endpoint URL):8182/gremlin'
graph = Graph()
g = graph.traversal().withRemote(DriverRemoteConnection(writer_url, 'g'))

In both cases, make sure your Neptune cluster's security group allows inbound traffic on port 8182 from your client's IP address or security group.

Also, even though you mentioned that IAM authentication is disabled, double-check your Neptune cluster's settings to ensure there are no other authentication mechanisms in place that might be preventing your connection.

If you're still encountering issues after these modifications, you may want to check your Neptune cluster's logs for any error messages that could provide more insight into the connection problems.
Sources
Using the Bolt protocol to make openCypher queries to Neptune - Amazon Neptune
Using Node.js to connect to a Neptune DB instance - Amazon Neptune

profile picture
answered a month ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions