serverless-websocket
v1.0.1
Published
Serverless websocket support using AWS IOT & Cognito. Similar to other services like Pusher & ably.
Downloads
10
Readme
Serverless Websocket
Serverless websocket support using AWS IOT & Cognito. Similar to other services like Pusher & ably.
This was designed primarily for the browser, but will also work in Node.js
The implementation is low-level and just covers getting the websocket URL. You'll probably want to use an MQTT client to connect to it.
Install
npm install serverless-websocket
Usage
const websocketURL = await Create({
accountID: accountID, // your 9+ digit AWS account ID (not access key)
identityPoolID: poolID, // Cognito Pool ID. See below for setup
endpoint: endpoint // Endpoint provided by Cognito, see below.
region: 'us-west-2',
})
// usage: you'll probably want to use a MQTT client
const ws = new WebSocket(websocketURL, ['mqttv3.1'])
How to
More coming soon, but for now you can refer to:
- https://github.com/kmamykin/aws-mqtt#aws-setup-and-security
- https://github.com/kmamykin/aws-mqtt/blob/master/src/createWebSocketStream.js
TODO
- [ ] Eliminate aws-signature-v4 dependency. This will allow us to use less of the crypto library.
- [ ] Simple MQTT client using https://github.com/mqttjs/mqtt-packet. Unfortunately, the MQTT clients are quite bloated in the browser, but the protocol is straightforward, so it wouldn't be hard to write a slim one on top of the standard websockets API.
Test
npm test
License
MIT