Created
October 22, 2016 12:10
-
-
Save marcelog/0cff0304f83ede051bdf982da6e2dc77 to your computer and use it in GitHub Desktop.
This AWS Lambda can be used to check your website for availability
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
'use strict'; | |
var url = require('url'); | |
var target = 'http://www.yourwebsite.com'; // Change this one | |
exports.handler = function(event, context, callback) { | |
var urlObject = url.parse(target); | |
var mod = require( | |
urlObject.protocol.substring(0, urlObject.protocol.length - 1) | |
); | |
console.log('[INFO] - Checking ' + target); | |
var req = mod.request(urlObject, function(res) { | |
res.setEncoding('utf8'); | |
res.on('data', function(chunk) { | |
console.log('[INFO] - Read body chunk'); | |
}); | |
res.on('end', function() { | |
console.log('[INFO] - Response end'); | |
callback(); | |
}); | |
}); | |
req.on('error', function(e) { | |
console.log('[ERROR] - ' + e.message); | |
callback(e); | |
}); | |
req.end(); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Do you really use this to monitor your website? Do you find Lambda reliable enough for such a purpose?