Closed azatTemirbek closed 3 weeks ago
Based on this blog post I would assume that the prebuilt Linux libraries are not compatible with Amazon Linux. So for now, you would have to setup a suitable build environment and compile better-sqlite3 for Amazon Linux on your own.
so basically when I am building layer I am using --use-container which is using public.ecr.aws/sam/build-nodejs18.x:latest-x86_64 Docker container image.
...
SqliteLayer:
Type: AWS::Serverless::LayerVersion
Metadata:
BuildMethod: makefile
Properties:
LayerName: "trakr-sqlite"
Description: Runtime dependencies for Lambdas
ContentUri: ./
CompatibleRuntimes:
- nodejs18.x
CompatibleArchitectures:
- arm64
RetentionPolicy: Delete
.PHONY: build-SqliteLayer
build-SqliteLayer:
mkdir -p "$(ARTIFACTS_DIR)/nodejs"
cp package-sqlite.json "$(ARTIFACTS_DIR)/nodejs/package.json"
npm install --production --legacy-peer-deps --prefix "$(ARTIFACTS_DIR)/nodejs/"
rm "$(ARTIFACTS_DIR)/nodejs/package.json"
.PHONY: pack
pack:
cd .aws-sam/build/SqliteLayer && zip -r trakr-sqlite-layer-v1.0.zip . && cp trakr-sqlite-layer-v1.0.zip ../../../
means I am building inside AWS container
sam build --use-container
Starting Build inside a container
Building layer 'SqliteLayer'
For container layer build, first compatible runtime is chosen as build target for container.
Fetching public.ecr.aws/sam/build-nodejs18.x:latest-x86_64 Docker container image......
Mounting ./trakr-layers as /tmp/samcli/source:ro,delegated, inside runtime container
and in the source code I see better-sqlite3 uses prebuild-install and bindings lib to build release when the packege is installed
...
"scripts": {
"install": "prebuild-install || node-gyp rebuild --release", // <=== building release on install
"build-release": "node-gyp rebuild --release",
"build-debug": "node-gyp rebuild --debug",
"rebuild-release": "npm run lzz && npm run build-release",
"rebuild-debug": "npm run lzz && npm run build-debug",
"test": "mocha --exit --slow=75 --timeout=5000",
"benchmark": "node benchmark",
"download": "bash ./deps/download.sh",
"lzz": "lzz -hx hpp -sx cpp -k BETTER_SQLITE3 -d -hl -sl -e ./src/better_sqlite3.lzz"
},
....
as a result I see the on the npm there is no build folder and inside layer it is exist which means native modules is build upon installation which is happening inside aws container (also tried inside cloud9 with AL 2023 image) error is same
ok I see prebuild-install is downloading from github but even after building it inside cloud9 and replacing the binary with my own binary I got same error
same same same error
And how does your Node project look like? In order to ensure that really your self compiled binary is loaded, I would ship it right next to your script files and pass it's path into the Database constructor using the nativeBinding option. Because otherwise, running install on your project might just overwrite the default binary location again.
@neoxpert after 2 days of digging seems I have been using arch incorrectly. Turns out after changing it to x86_64 on lambda config it is working ok.
Tried this combinations
Extra info
Sample output when function invoked: