0

I'm using the client.Client class from gremlin_python.driver to connect to AWS Neptune. See the following

    def _prepare_request(method, url, *, data=None, params=None, headers=None, service='neptune-db'):
        _ = requests.Session()
        request = requests.Request(method=method, url=url, data=data, params=params, headers=headers)

        credentials = Session().get_credentials()
        frozen_creds = credentials.get_frozen_credentials()

        req = AWSRequest(method=method, url=url, data=data, params=params, headers=headers)
        SigV4Auth(frozen_creds, service, os.environ['AWS_REGION']).add_auth(req)
        prepared_iam_req = req.prepare()
        request.headers = dict(prepared_iam_req.headers)
        return request.prepare()

    # https
    http_protocol = 'https'
    uri = f'{http_protocol}://{self.host}:{self.port}/gremlin'
    request = _prepare_request('GET', uri)

    # wss
    ws_url = 'wss://{}:{}/gremlin'.format(self.host, self.port)
    ws_request = httpclient.HTTPRequest(ws_url, headers=dict(request.headers))
    self.conn = client.Client(ws_request, 'g')

Now my question how can I used the client.Client object from above to get a traversal object "g".

There is a similar example at https://pypi.org/project/gremlinpython/#description showing this. But I can't use the DriverRemoteConnection in the above code.

>>> from gremlin_python.process.anonymous_traversal import traversal
>>> from gremlin_python.driver.driver_remote_connection import DriverRemoteConnection
>>> g = traversal().withRemote(DriverRemoteConnection('ws://localhost:8182/gremlin','g'))
stephen mallette
  • 45,298
  • 5
  • 67
  • 135
user1187968
  • 7,154
  • 16
  • 81
  • 152
  • 1
    Feels a bit like you're trying to recreate the wheel here. We already have a Neptune specific implementation of gremlin-python that helps with SigV4 signing here: https://github.com/awslabs/amazon-neptune-tools/tree/master/neptune-python-utils – Taylor Riggan Aug 19 '21 at 02:15

1 Answers1

1

Adding an answer in case others find this discussion.

When working with Amazon Neptune using Python, there is a nice open source set of utilities located here that make it easy to create SigV4 signed requests and perform many other common tasks.

Several of the examples are also useful with any Gremlin Server and not just Neptune.

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