o1lab / xmysql

xmysql is now https://github.com/nocodb/nocodb
https://github.com/nocodb/nocodb
MIT License
174 stars 55 forks source link

AWS lambda - sharing knowledge #1

Open Bnaya opened 5 years ago

Bnaya commented 5 years ago

I want to share my progress with integrating it with lambda, and also to ask related questions.

My use case is that i have existing serverless project, and i want to add xapi under specific route.

First you need to import colors = require("colors"); (or require if not typescript or whatever)

What works for me: I'm using https://github.com/awslabs/aws-serverless-express Which is the official lambda -> express compat layer (and not serverless-http)

And im mounting the express app that im passing to xapi under subroute

    const app = express();
    const topLevelApp = express();
    const r = await initializeXapi(app);
    topLevelApp.use("/expressApp", app);

in that way, xapi will have the correct path to itself

What am i missing: Due to lambda nature, it is expected to close any db connection after any request, or the lambda won't exit until timeout (30 secs for api gateway lambda) and we will get an error in the log. So we need a way to: or close destroy xpi, and create new one for each request, Or a way to "suspend"/"resume" it, that will close to mysql connection and restore it on demand.

Both ways have advantages and disadvantages (i can elaborate)

When i will finish to set up all of my stuff i will be happy to create an example project