Created
May 11, 2018 19:51
-
-
Save cdeutsch/a789811062a942e45b5f19ac0c9f9f6c to your computer and use it in GitHub Desktop.
Amazon AWS IOT Button to Webhook POST
This file contains hidden or 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
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