Skip to content

Instantly share code, notes, and snippets.

@zcaceres
Forked from groteworld/index.js
Created October 27, 2017 19:36
Show Gist options
  • Save zcaceres/cb14d6e3d8ba4a184ef0d2ac1b65d8d8 to your computer and use it in GitHub Desktop.
Save zcaceres/cb14d6e3d8ba4a184ef0d2ac1b65d8d8 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;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment