0

I am trying to connect with the AWS Neptune database using gremlinpython library from the AWS Lambda function.

from gremlin_python.driver import client

query = "g.V().count()"
uri = "wss://aws-neptune-endpoint:8182/gremlin"
clientt = client.Client(uri, 'g')
response = clientt.submit(query)
if response != None:
   print('Response is OK')
   return response.result()
else:
   print('Response is not good ')
   return None

Note: AWS Lambda function is outside of Neptune DB VPC. but When we are trying the following code, we are able to connect and get results.

from __future__  import print_function  # Python 2/3 compatibility
from gremlin_python.structure.graph import Graph
from gremlin_python.driver.driver_remote_connection import DriverRemoteConnection
from gremlin_python.driver import serializer
from gremlin_python.process.anonymous_traversal import traversal

graph = Graph()

remoteConn = DriverRemoteConnection('wss://aws-neptune-endpoint:8182/gremlin','g',
                                    pool_size=1,
    message_serializer=serializer.GraphSONSerializersV2d0())
g = traversal().withRemote(remoteConn)

print(g.V().hasLabel('Company'))
remoteConn.close()

Please help, Thanks in Advance

6
  • If your Lambda function is outside the VPC it will not be able to connect to Neptune unless you give it some other way to do so. When you say you get results, where do you run the code from? Commented Feb 1, 2022 at 14:33
  • I am getting result in case of using "DriverRemoteConnection" on my local machine. Commented Feb 1, 2022 at 14:58
  • OK, so when you run the code from a Lambda function, that Lambda function must be able to access the Neptune VPC. Commented Feb 1, 2022 at 15:04
  • yes, but that is not an option for me, as I am new to gremlin, I want to execute query string on Neptune server, which seems not possible or out of knowledge so I used client instance of gremlin_python module, which is working fine in Jupyter Notebook but unfortunately not working using lambda or the local machine. Commented Feb 1, 2022 at 15:08
  • I added an answer below Commented Feb 1, 2022 at 16:00

1 Answer 1

1

Amazon Neptune is a VPC only database. Any application using Neptune has to provide a way to access the VPC. There are many ways to do this, load balancer, Direct Connect, VPC peering, SSH tunnel, etc. But the application developer has to decide how to give access to the database. Neptune does not expose a public IP address.

There is some information about connecting to Neptune here

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the help @Kelvin, I will check it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.