Search code examples
javascriptaws-lambdatinkerpopamazon-neptunegremlin-server

Unable to commit transactions in AWS Neptune using an AWS Lambda written in javascript


I need to use gremlin transactions using the npm gremlin library. I went through the standard transaction syntax mentioned for javascript in the tinkerpop documentation - https://tinkerpop.apache.org/docs/current/reference/#gremlin-javascript-transactions. I'm using AWS Lambda for the same. I am keeping 1024MB of RAM with a 10 seconds timeout in my lambda. But my lambda is timing out all the time.

Following is my lambda function:

'use strict';

const gremlin = require('gremlin');
const { t: { id } } = gremlin.process;

exports.handler = async (event, context) => {
  const DriverRemoteConnection = gremlin.driver.DriverRemoteConnection;
  const g = gremlin.process.traversal().withRemote(new DriverRemoteConnection(`<ws_graph_url>:8182/gremlin`,{}));
  console.log('initializing the transaction');
  const tx = g.tx();
  console.log('beginning of the transaction');
  const gtx = tx.begin();
  try {
    let id1 = 'kanhai-test-tx-1', id2 = 'kanhai-test-tx-2';
    console.log('before ops');
    await Promise.all([
      gtx.addV('TX1').property(id, id1).iterate(),
      gtx.addV('TX2').property(id, id2).iterate(),
    ]);
    console.log('after tx ops');
    console.log('before tx commit');
    await tx.commit();
    console.log('after tx commit');
  } catch(err) {
    console.error('Failed to complete the transaction:', err);
    tx.rollback();
  }
};

The lambda times out during the execution of Promise.all() involving the 2 create operations.

If I remove the await from all the places, my lambda successfully runs in less than a second and successfully returns. All the log lines are printed as expected. But my operations don’t take place because I haven’t awaited for them.

But when I keep the await everywhere where I’ve mentioned, the last log line which is printed before my lambda times out is “before ops”, which is the log line just before my write operations which are inside a Promise.all.

This lambda is running in the same VPC where my Neptune cluster is hosted. I tried multiple queries without the transactions and they work successfully through gremlin as well as OpenCypher via HTTP.

I haven't found any concrete documentation which may help me in step by step execution of a successful transaction using javascript. Any help would be appreciated.


Solution

  • Support for bytecode transactions, g.tx() etc. requires a TinkerPop server version of 3.5.x - The first Neptune release to support that version is the 1.1.1.0 release (April 19th 2022). That is likely why your Lambda is not doing anything as the server does not support g.tx() at the Neptune 1.0.5.1 level. That older Neptune engine version is at the TinkerPop 3.4.11 level.

    The release notes for the 1.1.1.0 Neptune engine version are here: https://docs.aws.amazon.com/neptune/latest/userguide/engine-releases-1.1.1.0.html