Member-only story
Deploy Prisma to AWS Lambda with Node.js 18 on ARM64
On November 18, 2022, AWS announced support for Node.js v18 in AWS Lambda. If you want to run Prisma v4 on AWS Lambda using the Node.js v18 managed runtime and ARM64 architecture, and you already have a working setup in Node.js 14 or 16, there’s a crucial change to make.
In your schema.prisma file, update the binaryTargets to use the linux-arm64-openssl-1.1.x Prisma query engine binary. This adjustment will enable Prisma to run smoothly on the new Node.js v18 runtime with ARM64 architecture in AWS Lambda.
schema.prisma:
generator client {
provider = "prisma-client-js"
binaryTargets = ["native", "linux-arm64-openssl-1.1.x"]
}After modifying your schema.prisma file, update your Prisma client by running npx prisma generate. You might also want to delete any disused libquery files in your node_modules to avoid inflating your function’s deployment artifact. Check with ls ./node_modules/.prisma/client/libquery_engine-linux-arm64-*. For example, it’s probably safe to delete ./node_modules/.prisma/client/libquery_engine-linux-arm64-openssl-1.0.x.so.node.
After deploying to AWS Lambda, if your Lambda times out, make sure you’ve provisioned it enough memory. My own experience was that, a 128MB Lambda in Node.js 16 with the Prisma client would no longer start up in Node.js 18 until I increased the memory to 256MB. 💩
