Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

aws-mqtt-client

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

aws-mqtt-client

[AWS MQTT](http://docs.aws.amazon.com/iot/latest/developerguide/protocols.html) Websocket Pub/Sub with AWS IoT based on [MQTT.js](https://github.com/mqttjs/MQTT.js). Recently [AWS released support of WebSockets for IoT](https://aws.amazon.com/about-aws/wh

  • 0.0.6
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
278
decreased by-37.67%
Maintainers
1
Weekly downloads
 
Created
Source

AWS Websocket Pub/Sub client

AWS MQTT Websocket Pub/Sub with AWS IoT based on MQTT.js. Recently AWS released support of WebSockets for IoT service. It is very easy to use as Pub/Sub message system for serverless web applications. You can post new messages from AWS lambda function via http post request and receive them as websocket messages on client.

Installing it

npm i aws-mqtt-client --save

Basic usage

  1. Create an IAM role and asign predefined AWSIoTDataAccess policy. (It is better to use AWS Cognito to provide temporary credentials for the front-end application, you can also customize policy to allow access only to user specific topics).
  2. Run AWS CLI command aws iot describe-endpoint to get IoT endpoint url.
  3. Create mqttClient with AWS credentials.
import AWSMqtt from "aws-mqtt-client";

const mqttClient = new AWSMqtt({
  accessKeyId: AWS_ACCESS_KEY,
  secretAccessKey: AWS_SECRET_ACCESS_KEY,
  sessionToken: AWS_SESSION_TOKEN,
  endpointAddress: AWS_IOT_ENDPOINT_HOST,
  region: "us-east-1"
});
  1. Connect and receive messages from your topic.
mqttClient.on("connect", () => {
  mqttClient.subscribe("test-topic");
  console.log("connected to iot mqtt websocket");
});
mqttClient.on("message", (topic, message) => {
  console.log(message.toString());
});
  1. Publish a message.
mqttClient.publish(MQTT_TOPIC, message);

Complete MQTT.js API

Credits

Based on Serverless JS-Webapp Pub/Sub with AWS IoT article by Stefan Siegl. This library is a wrapper around MQTT.js npm package.

Keywords

FAQs

Package last updated on 01 Jun 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc