Last active
June 5, 2020 14:49
-
-
Save groteworld/af0577ea5c59e98843ef47325407da71 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
nevermind, I solved adding this to roles
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "iot:*" ], "Resource": [ "*" ] } ] }