C++ modules in NodeJS

I’m trying to use a sqlite module for node and the server crashes with the error below. It seems its having problems with one of the c++ bindings. What is needed to be done to get around this?

{“errorMessage”:"/var/lang/bin/…/lib/libstdc++.so.6: version `CXXABI_1.3.9’ not found (required by /var/task/node_modules/better-sqlite3/build/better_sqlite3.node)",“errorType”:“Error”,“stackTrace”:[“Module.load (module.js:565:32)”,“tryModuleLoad (module.js:505:12)”,“Function.Module._load (module.js:497:3)”,“Module.require (module.js:596:17)”,“require (internal/module.js:11:18)”,“Object. (/var/task/node_modules/better-sqlite3/lib/database.js:5:21)”,“Module._compile (module.js:652:30)”,“Object.Module._extensions…js (module.js:663:10)”,“Module.load (module.js:565:32)”]}

This is using a native C++ module that would need to be compiled against the AWS node docker image. There is a step by step tutorial on compiling binaries from lambda here: How to run Pandoc in AWS Lambda

Alternatively, you can try this pure js module node-sqlite-purejs - npm instead. This approach will likely be much simpler

Ref: node.js - Running SQLite3 on AWS Lambda - Stack Overflow

Followup question (out of curiosity):

What do you need sqlite in your function?

I see. What AMI and/or docker container should i be compiling against?

The reason for the sqlite db: It’s a read-only db that is populated / generated from our system of record. we push it out to a server that we can then download and use from mobile apps, nodejs, etc. For this serverless approach, I was planning on grabbing the db as part of a build step.

From what I can see on the latest lambda image sqlite is included yum list installed on amazon linux 2018.03 · GitHub

Try to set your runtime to 10x as described here https://twitter.com/DavidWells/status/1128693579595968512

How much data are you serving from DB? Perhaps you could approach this from flat file with fs.readFile or an alternative DB solution fauna/dynamo/s3 etc

1 Like

Upgrading to the new node 10x image worked. Thanks!