-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
32 lines (31 loc) · 1.03 KB
/
Copy pathindex.js
File metadata and controls
32 lines (31 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/**
* @file Node.js function boilerplate for Amazon Web Services Lambda.
* @author Victor Springer <victorspringer@gmail.com>
*/
const http = require('http');
/**
* @method
* @description The main method that will be fired.
* @param event - The JSON input with properties to be handled.
* @param context - The method's context.
* @param callback - The method's callback.
*/
exports.handler = (event, context, callback) => {
console.log(`starting ${event.name} job`);
http.get(event.url, (response) => {
console.log(`got response: ${response.statusCode}`);
if(response.statusCode >= 400) {
console.log(`${event.name} job failed`);
context.fail();
callback(new Error(`bad response from ${event.url}`));
return;
}
console.log(`${event.name} job finished successfully`);
context.succeed();
callback(null, `${event.name} job finished successfully`);
})
.on('error', (err) => {
console.log(err.message);
context.fail();
});
}