Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support nodejs14, nodejs16, updated better-sqlite3 package #4

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.serverless/
layer/
node_modules/
build/
build/
.idea
25 changes: 17 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# better-sqlite3 Lambda Layer

A [layer for AWS Lambda](https://aws.amazon.com/about-aws/whats-new/2018/11/aws-lambda-now-supports-custom-runtimes-and-layers/) that allows you to use [better-sqlite3](https://github.com/JoshuaWise/better-sqlite3) without having to compile any native modules. Just include this layer and then your code can access `better-sqlite3` normally when running in AWS Lambda.
A [layer for AWS Lambda](https://aws.amazon.com/about-aws/whats-new/2018/11/aws-lambda-now-supports-custom-runtimes-and-layers/)
that allows you to use [better-sqlite3](https://github.com/JoshuaWise/better-sqlite3) without having to compile any native modules. Just include this layer and then your code can access `better-sqlite3` normally when running in AWS Lambda.

It also serves as a template and example for using any native-compiled module with a nodejs lambda.

Expand All @@ -24,15 +25,20 @@ Clone this repo:

You can use the build script to build the layer directory:

./build.sh
RUNTIME=nodejs12 ./build.sh
RUNTIME=nodejs14 ./build.sh
RUNTIME=nodejs16 ./build.sh

Then use [serverless](https://serverless.com/framework/docs/providers/aws/guide/functions/#layers) to deploy the layer and example function to your own account:

sls deploy

RUNTIME=nodejs14 ./build.sh sls deploy

To build and deploy in one step:

npm run deploy
npm run deploy12
npm run deploy14
npm run deploy16

It should spit out the name of the ARN that you can use in your other lambdas.

Expand All @@ -48,7 +54,10 @@ Since currently all the production `node_modules` are included in the layer, the

## Version ARNs

| node.js version | better-sqlite3 version | ARN |
| --- | --- | --- |
| 12.x | 5.4.0 | arn:aws:lambda:us-east-1:284387765956:layer:BetterSqlite3:8 |
| 12.x | 6.0.1 | arn:aws:lambda:us-east-1:284387765956:layer:BetterSqlite3:9 |
| node.js version | better-sqlite3 version | ARN |
|-----------------| --- |------------------------------------------------------------------------|
| 12.x | 5.4.0 | arn:aws:lambda:us-east-1:284387765956:layer:BetterSqlite3:8 |
| 12.x | 6.0.1 | arn:aws:lambda:us-east-1:284387765956:layer:BetterSqlite3:9 |
| 12.x | 6.0.1 | arn:aws:lambda:us-east-1:833069544670:layer:better-sqlite3-nodejs12:1 |
| 14.x | 6.0.1 | arn:aws:lambda:us-east-1:833069544670:layer:better-sqlite3-nodejs14:1 |
| 16.x | 7.6.2 | arn:aws:lambda:us-east-1:833069544670:layer:better-sqlite3-nodejs16:1 |
4 changes: 2 additions & 2 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ set -e
rm -rf layer && mkdir -p layer/nodejs/node_modules

# Copies package.json to build directory
rm -rf build && mkdir build && cp package.json build && cp package-lock.json build
rm -rf build && mkdir build && cp package.json build

# Rebuilds native node modules using lambda environment
cd build
docker run --rm -v "$PWD":/var/task lambci/lambda:build-nodejs12.x npm install --only=prod
docker run --rm -v "$PWD":/var/task public.ecr.aws/sam/build-${RUNTIME}.x npm install --only=prod
cd ..

# Copies build into layer staging directory
Expand Down
Loading