[Publish message to AWS IoT] #tags: iot
const AWS = require('aws-sdk');
const config = require('@config');
publishMessage(topic, data) {
try {
const iotData = new AWS.IotData({
endpoint: config.iot.endpoint,
region: config.iot.region,
});
return iotData.publish({
topic,
payload: JSON.stringify(data),
}).promise();
} catch (err) {
throw err;
}
},