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:
{
"errorType":"TypeError","errorMessage":"bufferUtil2.mask is not a function",
"stack":[
"TypeError: bufferUtil2.mask is not a function",
"at bufferUtil$1.exports.mask (file:///var/task/dist/server/entry.mjs:111053:25)",
"at Sender.frame (file:///var/task/dist/server/entry.mjs:112347:11)",
"at Sender.send (file:///var/task/dist/server/entry.mjs:112536:20)",
"WebSocket2.send (file:///var/task/dist/server/entry.mjs:113273:22)",
"at Timeout._onTimeout (file:///var/task/dist/server/entry.mjs:109102:25)",
"at listOnTimeout (node:internal/timers:569:17)",
"at process.processTimers (node:internal/timers:512:7)"
]
}
{
"errorType":"TypeError","errorMessage":"bufferUtil2.mask is not a function",
"stack":[
"TypeError: bufferUtil2.mask is not a function",
"at bufferUtil$1.exports.mask (file:///var/task/dist/server/entry.mjs:111053:25)",
"at Sender.frame (file:///var/task/dist/server/entry.mjs:112347:11)",
"at Sender.send (file:///var/task/dist/server/entry.mjs:112536:20)",
"WebSocket2.send (file:///var/task/dist/server/entry.mjs:113273:22)",
"at Timeout._onTimeout (file:///var/task/dist/server/entry.mjs:109102:25)",
"at listOnTimeout (node:internal/timers:569:17)",
"at process.processTimers (node:internal/timers:512:7)"
]
}
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:
"optionalDependencies": {
"bufferutil": "^4.0.8"
}
"optionalDependencies": {
"bufferutil": "^4.0.8"
}
2 Replies
san4d
san4dOP11mo ago
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...
san4d
san4dOP11mo ago
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#neon
npm
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.
Want results from more Discord servers?
Add your server