Skip to content

Instantly share code, notes, and snippets.

@jadbox
Created September 22, 2018 22:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jadbox/5419a74ab643e525c1a97a96147f1407 to your computer and use it in GitHub Desktop.
Save jadbox/5419a74ab643e525c1a97a96147f1407 to your computer and use it in GitHub Desktop.
aws lambda iot
//import and prepare iot for pubsub
const IotData = require("aws-sdk/clients/iotdata");
let iotData;
export default function getIotData() {
if (iotData) {
return iotData;
} else {
iotData = new IotData({
endpoint: process.env["AWS_IOT_ENDPOINT"],
region: process.env["AWS_IOT_REGION"]
});
return iotData;
}
}
And then publish like so:
import getIotData from "./getIotData";
export default async function publishDataObjToChannel(channelName, payload) {
const iotData = getIotData();
const topic = channelName;
const iotParams = {
payload: JSON.stringify(payload),
topic,
qos: 0
};
return await iotData.publish(iotParams).promise();
}
https://github.com/aws-amplify/amplify-js/issues/1638
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment