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

Kelvin Lawrence
  • 14,674
  • 2
  • 16
  • 38
Ranjit Soni
  • 594
  • 6
  • 19
  • 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? – Kelvin Lawrence Feb 01 '22 at 14:33
  • I am getting result in case of using "DriverRemoteConnection" on my local machine. – Ranjit Soni Feb 01 '22 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. – Kelvin Lawrence Feb 01 '22 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. – Ranjit Soni Feb 01 '22 at 15:08
  • I added an answer below – Kelvin Lawrence Feb 01 '22 at 16:00
  • Sorry, It's my fault,,,its not working in either case. – Ranjit Soni Feb 01 '22 at 17:17

1 Answers1

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

Kelvin Lawrence
  • 14,674
  • 2
  • 16
  • 38