Skip to content

Instantly share code, notes, and snippets.

@johnypony3
Last active January 11, 2017 22:48
Show Gist options
  • Save johnypony3/f06c2f5e32646e0e985bfba0fa671979 to your computer and use it in GitHub Desktop.
Save johnypony3/f06c2f5e32646e0e985bfba0fa671979 to your computer and use it in GitHub Desktop.
a labda function that subscribes to an sns queue and pushes data to an mqtt queue
'use strict';
let publishTopic = require("./publishTopic");
exports.handler = (event, context, callback) => {
console.log('topic:', event.topic);
console.log('action:', event.action);
var topic = "***YOUR TOPIC***" + event.topic;
var action = event.action;
publishTopic([topic, action]);
//callback(null, "action: " + actionApi + " published to: " + topic);
callback(null, "{'status':'ok'}");
};
"use strict"
var mqtt = require('mqtt');
module.exports = (req, done) => {
var client = mqtt.connect("***YOUR ENDPOINT***")
client.on('connect', () => {
console.log("Connected");
console.log(req[0]);
console.log(req[1]);
client.publish(req[0],req[1]);
client.end();
console.log("published");
//req.result = "Successfully";
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment