Skip to content

Instantly share code, notes, and snippets.

@cdeutsch
Created May 11, 2018 19:51
Show Gist options
  • Save cdeutsch/a789811062a942e45b5f19ac0c9f9f6c to your computer and use it in GitHub Desktop.
Save cdeutsch/a789811062a942e45b5f19ac0c9f9f6c to your computer and use it in GitHub Desktop.
Amazon AWS IOT Button to Webhook POST
const https = require('https');
const querystring = require('querystring');
exports.handler = (event, context, callback) => {
console.log('Received event:', event);
const postData = querystring.stringify({});
const options = {
hostname: 'my-glitch.glitch.me',
port: 443,
path: '/my-path',
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Content-Length': postData.length
}
};
const req = https.request(options, (res) => {
let body = '';
console.log(`STATUS: ${res.statusCode}`);
res.on('data', (chunk) => body += chunk);
res.on('end', () => {
console.log('Event has been sent to Webhook');
callback(null, body);
});
}).on('error', (e) => {
console.log('Failed to trigger Webhook', e);
callback(`Failed to trigger Webhook: ${e.message}`);
});
req.write(postData);
req.end();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment