Registry / devops / aws-lambda-ws-server

aws-lambda-ws-server

JSON →
library0.1.21jsnpmunverified

A websocket server library designed for AWS Lambda and local development, version 0.1.21. It provides a simple handler-based API for connect, disconnect, default, and message events, automatically managing API Gateway WebSocket integrations. Key differentiator: works seamlessly both in AWS Lambda and locally, enabling testing without deployment. The package is lightweight, uses StandardJS style, and has no external dependencies. Release cadence is low (last update appears old). Supports Node.js only.

npm install aws-lambda-ws-server
INSTALL
IMPORT
SIG · AWS-LAMBDA-WS-SERV
A
aws-lambda-ws-server
devopsjavascriptv0.1.21
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default export
const ws = require('aws-lambda-ws-server')
import ws from 'aws-lambda-ws-server'
Package is CJS-only; ESM import will fail. Use require() or dynamic import().
ws.handler
const ws = require('aws-lambda-ws-server') ws.handler({...})
const { handler } = require('aws-lambda-ws-server')
The module exports a function 'ws' which also has a 'handler' method. Destructuring may break if not careful.
TypeScript usage
const ws = require('aws-lambda-ws-server')
import ws from 'aws-lambda-ws-server'
No TypeScript declarations included. Use @types/aws-lambda for context types.

Shows full setup of a WebSocket handler for AWS Lambda with connect, disconnect, default, and message events, including echoing messages back.

const ws = require('aws-lambda-ws-server') exports.handler = ws( ws.handler({ async connect ({ id }) { console.log('connection %s', id) return { statusCode: 200 } }, async disconnect ({ id }) { console.log('disconnect %s', id) return { statusCode: 200 } }, async default ({ message, id }) { console.log('default message', message, id) return { statusCode: 200 } }, async message ({ message, id, context }) { const { postToConnection } = context console.log('message', message, id) await postToConnection({ message: 'echo' }, id) return { statusCode: 200 } } }) )
Debug
Known issues
gotchaPackage has no TypeScript definitions; using in TypeScript project will require custom type declarations.
fix
Create a .d.ts file or use @types/aws-lambda for context.
affects: >=0.0.0
gotchaESM import (import ws from '...') does not work; the package uses CommonJS only.
fix
Use require() or dynamic import() in ESM context.
affects: >=0.0.0
gotchaThe module exports a function (ws) that also has a .handler property. Confusing when destructuring.
fix
Access ws.handler from the default export, not by destructuring.
affects: >=0.0.0
deprecatedTravis CI badge in README; repository may not be actively maintained.
fix
Check latest commit or consider alternative packages.
affects: >=0.0.0
Errors
Common errors & fixes
TypeError: ws is not a function
Using import statement instead of require() – package is CJS-only.
fix
Replace 'import ws from "aws-lambda-ws-server"' with 'const ws = require("aws-lambda-ws-server")'
Cannot find module 'aws-lambda-ws-server'
Package not installed or missing from node_modules.
fix
Run npm install aws-lambda-ws-server --save
TypeError: Cannot destructure property 'handler' of '...' as it is undefined.
Attempting to destructure 'handler' from the module instead of accessing it via the default export.
fix
Use: const ws = require('aws-lambda-ws-server'); ws.handler({...})
Upgrade
Version history
0.1.21latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
13 hits · last 30 days
node
10
Amazon
1
OpenAI (training)
1
Resources
aws-lambda-ws-server — npm install aws-lambda-ws-server · libregistry