【问题标题】:Getting timeout error while connecting with AWS Neptune database from lambda function从 lambda 函数连接 AWS Neptune 数据库时出现超时错误
【发布时间】: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


【解决方案1】:

Amazon Neptune 是一个仅限 VPC 的数据库。任何使用 Neptune 的应用程序都必须提供访问 VPC 的方法。有很多方法可以做到这一点,负载均衡器、直接连接、VPC 对等互连、SSH 隧道等。但应用程序开发人员必须决定如何授予对数据库的访问权限。 Neptune 不会公开公共 IP 地址。

有一些关于连接海王星here的信息

【讨论】:

  • 感谢@Kelvin 的帮助,我会检查的。
猜你喜欢
  • 1970-01-01
  • 2021-04-27
  • 1970-01-01
  • 1970-01-01
  • 2017-10-05
  • 2019-03-08
  • 2018-09-03
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多