aws-lambda-ws-server

0.1.21 • Public • Published

aws-lambda-ws-server

js-standard-style build status downloads

AWS Lambda Websocket Server.

usage

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

Package Sidebar

Install

npm i aws-lambda-ws-server

Weekly Downloads

181

Version

0.1.21

License

Apache-2.0

Unpacked Size

29.7 kB

Total Files

7

Last publish

Collaborators

  • jameskyburz