Error when making a websocket-based transaction on an AWS Lambda Function
Problem
I'm seeing this error when I try to make a connection:
I'm able to make HTTP calls no problem.
Setup
- Node 18.v20 Runtime on AWS Lambda
- Postgres 16 on Neon
- @Neondatabase/serverless v0.6.1
- drizzle-orm v0.29.3
- ws v8.16.0
Ask
Has anyone ran into this before? If so, what did you you need to change? I'm looking into the
bufferUtil2.mask
error currently.
Solution
I figured out that I needed to add bufferutil as an optional dependency:
2 Replies
I found this in the neon docs (https://neon.tech/docs/serverless/serverless-driver#use-the-driver-over-websockets):
Please note that Drizzle Kit does not support the Neon serverless driver — you'll have to use a standard Postgres driver with Drizzle Kit, like node-postgres or postgres.js.Is this still accurate?
Neon
Neon serverless driver - Neon Docs
The Neon serverless driver is a low latency Postgres driver for JavaScript and TypeScript that allows you to query data from serverless and edge environments over HTTP or WebSockets in place of TCP. T...
Updated my question with the solution: adding bufferutil. I learned about it on the
ws
npm docs:
https://www.npmjs.com/package/ws#opt-in-for-performance
Could be worth updating the drizzle docs somewhere.:
https://orm.drizzle.team/docs/get-started-postgresql#neonnpm
ws
Simple to use, blazing fast and thoroughly tested websocket client and server for Node.js. Latest version: 8.16.0, last published: a month ago. Start using ws in your project by running
npm i ws
. There are 17068 other projects in the npm registry using ws.Drizzle ORM - next gen TypeScript ORM
Drizzle ORM is a lightweight and performant TypeScript ORM with developer experience in mind.