Skip to content

Instantly share code, notes, and snippets.

@LosantGists
Last active December 13, 2016 02:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LosantGists/bf4423a9a456ad3d694667988953f21a to your computer and use it in GitHub Desktop.
Save LosantGists/bf4423a9a456ad3d694667988953f21a to your computer and use it in GitHub Desktop.
Lambda function to invoke Losant webhook.
var https = require('https');
exports.handler = (event, context, callback) => {
var postData = JSON.stringify(event);
var options = {
hostname: 'triggers.losant.com',
port: 443,
path: '/webhooks/my-webhook-id',
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Content-Length': Buffer.byteLength(postData)
}
};
var req = https.request(options, (res) => {
console.log(`STATUS: ${res.statusCode}`);
console.log(`HEADERS: ${JSON.stringify(res.headers)}`);
res.setEncoding('utf8');
res.on('data', (chunk) => {
console.log(`BODY: ${chunk}`);
});
res.on('end', () => {
callback();
});
});
req.on('error', (e) => {
console.log(`problem with request: ${e.message}`);
callback();
});
// write data to request body
req.write(postData);
req.end();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment