【发布时间】:2022-02-02 00:00:10
【问题描述】:
我正在尝试使用 AWS Lambda 函数中的 gremlinpython 库连接 AWS Neptune 数据库。
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
注意:AWS Lambda 函数位于 Neptune DB VPC 之外。 但是当我们尝试以下代码时,我们能够连接并获得结果。
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()
请帮忙,在此先感谢
【问题讨论】:
-
如果您的 Lambda 函数在 VPC 之外,它将无法连接到 Neptune,除非您提供其他方式来连接。当你说你得到结果时,你从哪里运行代码?
-
如果在我的本地机器上使用“DriverRemoteConnection”,我会得到结果。
-
好的,所以当您从 Lambda 函数运行代码时,该 Lambda 函数必须能够访问 Neptune VPC。
-
是的,但这对我来说不是一个选项,因为我是 gremlin 的新手,我想在 Neptune 服务器上执行查询字符串,这似乎不可能或不知道所以我使用了客户端实例gremlin_python 模块,它在 Jupyter Notebook 中运行良好,但不幸的是不能使用 lambda 或本地机器。
-
我在下面添加了答案
标签: amazon-web-services amazon-neptune gremlinpython