I am trying to run a query against a Neo4j database from an AWS Lambda function.
The Lambda appears to get a driver and session OK, but then freezes waiting for the transaction to start. Eventually the Lambda times out and returns a failure.
I have tried numerous combinations of session/driver and transaction, none of which gets past starting the transaction. I've even tried compiling with JDK 8 and 11, to no avail.
This is the simplest form I've tried:
public LambdaResponse handleRequest(Map<String, Object> i, Context cntxt) {
try {
System.out.println("handleRequest begins...");
System.out.println("Request id: " + cntxt.getAwsRequestId());
Driver driver = GraphDatabase.driver("bolt://xxx.xxx.xxx.xxx:7687", AuthTokens.basic("xxxxxxxxxxxxxx", "xxxxxxxxxxxxxxxx"));
System.out.println("Driver aquired: " + driver.toString());
Session session = driver.session();
System.out.println("Session aquired: " + session.toString());
Result queryResult = session.run("MATCH (n:Version) "
+ "RETURN date as Date, loaded as Loaded ");
System.out.println("Processing result set...");
while (queryResult.hasNext()) {
Record record = queryResult.next();
System.out.println("record " + record.toString());
}
} catch (Exception e) {
e.printStackTrace(System.out);
}
LambdaResponse responseL = new LambdaResponse(ppGetVersion());
responseL.setStatusCode(200);
System.out.println("...ends");
return responseL;
}
The Lambda journal looks like this:
14:52:52 INFO: Direct driver instance 1032986144 created for server address xxx.xxx.xxx.xxx:7687
14:52:52 Driver aquired: org.neo4j.driver.internal.InternalDriver@3d921e20
14:52:52 Session aquired: org.neo4j.driver.internal.InternalSession@27808f31
14:53:01 END RequestId: aac2f2e1-039e-4614-9fa3-f089f5daafc6
14:53:01 REPORT RequestId: aac2f2e1-039e-4614-9fa3-f089f5daafc6 Duration: 10010.21 ms Billed Duration: 10000 ms Memory Size: 2048 MB Max Memory Used: 117 MB Init Duration: 324.79 ms
14:53:01 2020-05-17T14:53:01.609Z aac2f2e1-039e-4614-9fa3-f089f5daafc6 Task timed out after 10.01 seconds
As you can see, it never gets as far as reporting the query results before the lambda times out. There is no exception thrown and nothing logged in any of the Neo4j log files - absolutely zip.
I've tried this whith more granular code that explicitly tries to start a transaction and it never gets past that point.
This code runs perfectly well on an EC2 instance. It's only when callled from the Lambda it hangs.
I'm running on enterprise db version 4.0.0 and using the 4.0.0 java driver (in Maven)
Even if no one has an answer I would be interested to hear from anyone who has had a success with Neo4j and Java Lambdas.
Regards,
Mark