Skip to content

Instantly share code, notes, and snippets.

@groteworld
Last active June 5, 2020 14:49
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save groteworld/af0577ea5c59e98843ef47325407da71 to your computer and use it in GitHub Desktop.
Save groteworld/af0577ea5c59e98843ef47325407da71 to your computer and use it in GitHub Desktop.
Example aws/aws-sdk-js IotData API Lambda usage
// 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;
@CuyiGuaton
Copy link

nevermind, I solved adding this to roles

{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "iot:*" ], "Resource": [ "*" ] } ] }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment