Skip to content

Instantly share code, notes, and snippets.

@johngidt
Forked from marcelog/lambda-website-checker.js
Created February 8, 2018 17:11
Show Gist options
  • Save johngidt/d81f6538e9d43d2d2142679371533f2c to your computer and use it in GitHub Desktop.
Save johngidt/d81f6538e9d43d2d2142679371533f2c to your computer and use it in GitHub Desktop.
This AWS Lambda can be used to check your website for availability
'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