mirror of
https://github.com/serverless/serverless.git
synced 2026-01-18 14:58:43 +00:00
26 lines
571 B
JavaScript
26 lines
571 B
JavaScript
'use strict';
|
|
|
|
const AWS = require('aws-sdk');
|
|
const { region, persistentRequest } = require('../misc');
|
|
|
|
function publishIotData(topic, message) {
|
|
const Iot = new AWS.Iot({ region });
|
|
|
|
return Iot.describeEndpoint()
|
|
.promise()
|
|
.then(data => {
|
|
const IotData = new AWS.IotData({ region, endpoint: data.endpointAddress });
|
|
|
|
const params = {
|
|
topic,
|
|
payload: Buffer.from(message),
|
|
};
|
|
|
|
return IotData.publish(params).promise();
|
|
});
|
|
}
|
|
|
|
module.exports = {
|
|
publishIotData: persistentRequest.bind(this, publishIotData),
|
|
};
|