Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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: 12 days ago
JSON representation

aws lambda websocket server.

Awesome Lists containing this project

README

        

# aws-lambda-ws-server

[![js-standard-style](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://github.com/feross/standard)
[![build status](https://api.travis-ci.org/JamesKyburz/aws-lambda-ws-server.svg)](https://travis-ci.org/JamesKyburz/aws-lambda-ws-server)
[![downloads](https://img.shields.io/npm/dm/aws-lambda-ws-server.svg)](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)