forked from andrewpuch/lambda_example
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlambda.js
50 lines (40 loc) · 1.75 KB
/
lambda.js
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
'use strict';
/**
*
* Author: Andrew Puch
*
* Description: In this simple example we are going to parse the RSS feed for
* AWS EC2 East and return the first item in the feeds title. We will console
* log out the content so that the lambda logs can show the respose.
*
*/
var request = require('request'),
xml = require('xml2js').parseString;
exports.rss = function(event, context, callback) {
request('http://status.aws.amazon.com/rss/ec2-us-east-1.rss', function (error, response, body) {
if(!error && response.statusCode == 200) {
xml(body, { trim : true }, function (error, result) {
if(error) {
console.log("Error parsing data.");
// This will be used for when we hook up API Gateway.
// It does no harm just being here for the Lambda only tutorial.
context.done(null, { message : error });
return;
}
var content = "\n\nAWS EC2 us-east-1\n";
content = content + "-----------------\n";
content = content + result.rss.channel[0].item[0].title[0]._ + "\n";
console.log(content);
// This will be used for when we hook up API Gateway.
// It does no harm just being here for the Lambda only tutorial.
context.done(null, { message : result.rss.channel[0].item[0].title[0]._ });
return;
});
} else {
console.log("Error receiving data.");
// This will be used for when we hook up API Gateway.
// It does no harm just being here for the Lambda only tutorial.
context.done(null, { message : error });
}
});
};