Skip to content

Instantly share code, notes, and snippets.

@jaxoncreed
Created August 22, 2018 00:00
Show Gist options
  • Save jaxoncreed/d54e029c9fb062f18e4190b5ee32694e to your computer and use it in GitHub Desktop.
Save jaxoncreed/d54e029c9fb062f18e4190b5ee32694e to your computer and use it in GitHub Desktop.
const AWS = require('aws-sdk');
var endpoint = new AWS.Endpoint('https://search-arduino-test-ybrxss46t4wvvczoi5tipwrvz4.us-west-2.es.amazonaws.com');
var path = require('path');
const https = require('https');
var esDomain = {
region: 'us-west-2',
endpoint: 'search-arduino-test-ybrxss46t4wvvczoi5tipwrvz4.us-west-2.es.amazonaws.com/',
index: 'arduinoindex',
doctype: 'breath'
};
exports.handler = function(event, context) {
return new Promise((resolve, reject) => {
const options = {
host: 'search-arduino-test-ybrxss46t4wvvczoi5tipwrvz4.us-west-2.es.amazonaws.com',
path: '/arduinoindex/ArduinoType/',
port: 443,
method: 'POST',
headers: {
'Content-Type': 'application/json'
}
};
const req = https.request(options, (res) => {
console.log(res.headers);
resolve('Success');
});
req.on('error', (e) => {
console.log(e.message);
reject(e.message);
});
event.date = + new Date().getTime();
console.log(event);
// send the request
req.write(JSON.stringify(event));
req.end();
setTimeout(function() {
// send request to ES for latest document... function(res) {
// https://nodejs.org/api/https.html#https_https_request_url_options_callback
// var data = '';
// res.on('data', function(d) {
// data += d;
// });
// res.on('end', function() {
// var json = JSON.stringify(data);
// if (JSON.data is more than 5 seconds ago) {
// send sms
// }
// })
// }
} , 5000);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment