Last active
March 5, 2016 23:46
-
-
Save nzoschke/af3a039ae408fa2deb16 to your computer and use it in GitHub Desktop.
Lambda Canary
This file contains 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
var http = require('http'); | |
exports.handler = function(event, context) { | |
// return success before 5m | |
console.log("setTimeout start"); | |
setTimeout(function(){ | |
console.log('setTimeout 290s finish'); | |
context.succeed('setTimeout 290s finish'); | |
}, 290000); | |
// every 1 second request and record response | |
setInterval(function() { | |
var start = new Date(); | |
var req = http.request({ | |
hostname: 'httpd-1804309553.us-east-1.elb.amazonaws.com', | |
method: 'GET', | |
path: '/', | |
port: 80, | |
}, function(res) { | |
var body = ''; | |
console.log('Status:', res.statusCode); | |
console.log('Headers:', JSON.stringify(res.headers)); | |
res.setEncoding('utf8'); | |
res.on('data', function(chunk) { | |
body += chunk; | |
}); | |
res.on('end', function() { | |
console.log('Body:', body); | |
console.log('Time:', new Date() - start, 'ms'); | |
}); | |
}); | |
req.on('error', function(e) { | |
console.log('Error:', e); | |
}); | |
req.on('timeout', function() { | |
console.log('Timeout'); | |
req.abort(); | |
}); | |
req.end(); | |
}, 1000); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment