ZhuangER
9/14/2018 - 10:15 PM

[Publish message to AWS IoT] #tags: iot

[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;
  }
},