-
-
Save zcaceres/cb14d6e3d8ba4a184ef0d2ac1b65d8d8 to your computer and use it in GitHub Desktop.
Example aws/aws-sdk-js IotData API Lambda usage
This file contains 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
// An usage of AWS.IotData in Lambdas | |
// | |
// This example assumes some things | |
// 1. That you have a environment variable AWS_IOT_ENDPOINT. This is the url that you can find in AWS IoT dashboard settings | |
// 2. The lambda and your aws iot devices are on the same account and region | |
const AWS = require('aws-sdk'); | |
const iotData = new AWS.IotData({ endpoint: process.env.AWS_IOT_ENDPOINT }); | |
const handler = (event, context) => { | |
const params = { | |
topic: 'my/cool/topic', | |
payload: JSON.stringify(event) | |
} | |
iotData.publish(params, (err, res) => { | |
if (err) return context.fail(err); | |
console.log(res); | |
return context.succeed(); | |
}); | |
}; | |
exports.handler = handler; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment