2
votes

I am trying to execute lambda function on AWS neptune using gremlin python. Its hitting me gremlin-python is not an available GremlinScriptEngine. Can someone help on how to fix this. g.V().out().map(lambda: "lambda x: len(x.get().value('event'))").toList()

Each vertex in the graph contains an event property which is text

Query executed: g.V().out().map(lambda: "lambda x: len(x.get().value('event'))").toList() Stacktrace:

GremlinServerError                        Traceback (most recent call last)
<ipython-input-392-602123a0a83a> in <module>()
----> 1 g.V().out().map(lambda: "lambda x: len(x.get().value('event'))").toList()

/usr/local/lib/python3.7/site-packages/gremlin_python/process/traversal.py in toList(self)
     55 
     56     def toList(self):
---> 57         return list(iter(self))
     58 
     59     def toSet(self):

/usr/local/lib/python3.7/site-packages/gremlin_python/process/traversal.py in __next__(self)
     45     def __next__(self):
     46         if self.traversers is None:
---> 47             self.traversal_strategies.apply_strategies(self)
     48         if self.last_traverser is None:
     49             self.last_traverser = next(self.traversers)

/usr/local/lib/python3.7/site-packages/gremlin_python/process/traversal.py in apply_strategies(self, traversal)
    504     def apply_strategies(self, traversal):
    505         for traversal_strategy in self.traversal_strategies:
--> 506             traversal_strategy.apply(traversal)
    507 
    508     def apply_async_strategies(self, traversal):

/usr/local/lib/python3.7/site-packages/gremlin_python/driver/remote_connection.py in apply(self, traversal)
    146     def apply(self, traversal):
    147         if traversal.traversers is None:
--> 148             remote_traversal = self.remote_connection.submit(traversal.bytecode)
    149             traversal.remote_results = remote_traversal
    150             traversal.side_effects = remote_traversal.side_effects

/usr/local/lib/python3.7/site-packages/gremlin_python/driver/driver_remote_connection.py in submit(self, bytecode)
     52     def submit(self, bytecode):
     53         result_set = self._client.submit(bytecode)
---> 54         results = result_set.all().result()
     55         side_effects = RemoteTraversalSideEffects(result_set.request_id, self._client,
     56                                                   result_set.status_attributes)

/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/lib/python3.7/concurrent/futures/_base.py in result(self, timeout)
    430                 raise CancelledError()
    431             elif self._state == FINISHED:
--> 432                 return self.__get_result()
    433             else:
    434                 raise TimeoutError()

/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/lib/python3.7/concurrent/futures/_base.py in __get_result(self)
    382     def __get_result(self):
    383         if self._exception:
--> 384             raise self._exception
    385         else:
    386             return self._result

/usr/local/lib/python3.7/site-packages/gremlin_python/driver/resultset.py in cb(f)
     88         def cb(f):
     89             try:
---> 90                 f.result()
     91             except Exception as e:
     92                 future.set_exception(e)

/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/lib/python3.7/concurrent/futures/_base.py in result(self, timeout)
    423                 raise CancelledError()
    424             elif self._state == FINISHED:
--> 425                 return self.__get_result()
    426 
    427             self._condition.wait(timeout)

/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/lib/python3.7/concurrent/futures/_base.py in __get_result(self)
    382     def __get_result(self):
    383         if self._exception:
--> 384             raise self._exception
    385         else:
    386             return self._result

/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/lib/python3.7/concurrent/futures/thread.py in run(self)
     55 
     56         try:
---> 57             result = self.fn(*self.args, **self.kwargs)
     58         except BaseException as exc:
     59             self.future.set_exception(exc)

/usr/local/lib/python3.7/site-packages/gremlin_python/driver/connection.py in _receive(self)
     78             while True:
     79                 data = self._transport.read()
---> 80                 status_code = self._protocol.data_received(data, self._results)
     81                 if status_code != 206:
     82                     break

/usr/local/lib/python3.7/site-packages/gremlin_python/driver/protocol.py in data_received(self, message, results_dict)
    108         else:
    109             del results_dict[request_id]
--> 110             raise GremlinServerError(message["status"])

GremlinServerError: 599: {"requestId":"b8d8ea20-bcab-4350-94f3-47611fac704a","code":"InternalFailureException","detailedMessage":"gremlin-python is not an available GremlinScriptEngine"}```
2
Are you able to issue even a simple query successfully such as g.V().limit(1).count().next() ? I assume you built a ZIP file containing your code plus the Python dependencies such as gremlin-python and uploaded that to Lambda?Kelvin Lawrence
Hi Sross, do you mind accepting one of the answers here? Do let us know if you need more info on something.The-Big-K

2 Answers

1
votes

Amazon Neptune does not allow any script engines for security reasons. The documentation [1] does not call out script engines specifically, but it mentions that Neptune does not support Lambda's and groovy scripts for example.

[1] https://docs.aws.amazon.com/neptune/latest/userguide/access-graph-gremlin-differences.html

0
votes

I'd be surprised if the gremlin-python script engine was available on Neptune. As it is, even with Gremlin Server, gremlin-python is not installed by default and only available as plugin that you directly install to Gremlin Server.

I would say that the answer is to submit your lambdas as Groovy scripts like:

g.V().out().map(lambda: ("it.get().value('name').length()", "gremlin-groovy")).sum().toList()

but in general, Neptune doesn't support lambdas at all so it's doubtful that this would even work. I think that you will have to figure out how to write your traversal without this capability.