Created
September 22, 2018 22:16
-
-
Save jadbox/5419a74ab643e525c1a97a96147f1407 to your computer and use it in GitHub Desktop.
aws lambda iot
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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