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.
npm install aws-mqtt-client --save
AWSIoTDataAccesspolicy. (It is better to use AWS Cognito to provide temprerary credentiels for the front-end application, you can also customize policy to allow access only to user specific topics)
aws iot describe-endpointto get IoT endpoint url.
mqttClientwith AWS credentials
const mqttClient =accessKeyId: AWS_ACCESS_KEYsecretAccessKey: AWS_SECRET_ACCESS_KEYsessionToken: AWS_SESSION_TOKENendpointAddress: AWS_IOT_ENDPOINT_HOSTregion: 'us-east-1';