├── README.md ├── package.json └── lambda.js /README.md: -------------------------------------------------------------------------------- 1 | # Lambda Example 2 | Quick example of using Lambda. I am committing my node_modules folder so it's easy for everyone to pull down and zip up but I do not recommend doing that for when you are committing code to your repository. You should always include it in your .gitignore. 3 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "awstutorialseries", 3 | "version": "1.0.0", 4 | "description": "Simple lambda example.", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "author": "Andrew Puch", 10 | "license": "ISC", 11 | "dependencies": { 12 | "request": "^2.74.0", 13 | "xml2js": "^0.4.17" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /lambda.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | /** 4 | * 5 | * Author: Andrew Puch 6 | * 7 | * Description: In this simple example we are going to parse the RSS feed for 8 | * AWS EC2 East and return the first item in the feeds title. We will console 9 | * log out the content so that the lambda logs can show the respose. 10 | * 11 | */ 12 | 13 | var request = require('request'), 14 | xml = require('xml2js').parseString; 15 | 16 | exports.rss = function(event, context, callback) { 17 | request('http://status.aws.amazon.com/rss/ec2-us-east-1.rss', function (error, response, body) { 18 | if(!error && response.statusCode == 200) { 19 | xml(body, { trim : true }, function (error, result) { 20 | if(error) { 21 | console.log("Error parsing data."); 22 | 23 | // This will be used for when we hook up API Gateway. 24 | // It does no harm just being here for the Lambda only tutorial. 25 | context.done(null, { message : error }); 26 | 27 | return; 28 | } 29 | 30 | var content = "\n\nAWS EC2 us-east-1\n"; 31 | content = content + "-----------------\n"; 32 | content = content + result.rss.channel[0].item[0].title[0]._ + "\n"; 33 | 34 | console.log(content); 35 | 36 | // This will be used for when we hook up API Gateway. 37 | // It does no harm just being here for the Lambda only tutorial. 38 | context.done(null, { message : result.rss.channel[0].item[0].title[0]._ }); 39 | 40 | return; 41 | }); 42 | } else { 43 | console.log("Error receiving data."); 44 | 45 | // This will be used for when we hook up API Gateway. 46 | // It does no harm just being here for the Lambda only tutorial. 47 | context.done(null, { message : error }); 48 | } 49 | }); 50 | }; --------------------------------------------------------------------------------