https://github.com/jameskyburz/aws-lambda-ws-server
aws lambda websocket server.
https://github.com/jameskyburz/aws-lambda-ws-server
apigateway aws lambda websocket ws
Last synced: 4 months ago
JSON representation
aws lambda websocket server.
- Host: GitHub
- URL: https://github.com/jameskyburz/aws-lambda-ws-server
- Owner: JamesKyburz
- License: apache-2.0
- Created: 2019-01-09T14:23:14.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2021-04-29T21:33:51.000Z (over 4 years ago)
- Last Synced: 2025-04-14T12:54:22.802Z (6 months ago)
- Topics: apigateway, aws, lambda, websocket, ws
- Language: JavaScript
- Homepage: https://npm.im/aws-lambda-ws-server
- Size: 134 KB
- Stars: 40
- Watchers: 1
- Forks: 2
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# aws-lambda-ws-server
[](https://github.com/feross/standard)
[](https://travis-ci.org/JamesKyburz/aws-lambda-ws-server)
[](https://npmjs.org/package/aws-lambda-ws-server)AWS Lambda Websocket Server.
### usage
```javascript
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 }
}
})
)
```Works locally and in a lambda function.
# license
[Apache License, Version 2.0](LICENSE)