Reputation: 2297
AWS Lambda spins up and spins down execution environments on every request. Is it OK to open and close a driver connection to neo4j on each of those requests? This could be many times a second, in parallel - could this cause problems or performance degradation? If so, are there workarounds or is Lambda simply not a suitable environment for interacting with Neo4j?
Example Lambda that runs on every request:
// load neo4j javascript lib
const neo4j = require('neo4j-driver').v1;
// open connection to neo4j
const driver = neo4j.driver("bolt://localhost", neo4j.auth.basic("neo4j", "neo4j"));
/*
run some code
*/
// close connection to neo4j
driver.close();
Upvotes: 2
Views: 258
Reputation: 2798
Due to Lambda running in a container environment, containers will stay in memory for a period of time and thus be able to keep connection objects in memory if they are at a global scope. This would be an option in your case although you have no control over the lifetime of any given container.
Upvotes: 1