Skip to content
This repository was archived by the owner on Oct 9, 2021. It is now read-only.

Commit 233dcf6

Browse files
committed
initial commit
1 parent 1773a95 commit 233dcf6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+1993
-2
lines changed

CloudFormation/CreateZombieWorkshop.json

Lines changed: 509 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
var AWS = require('aws-sdk');
2+
var path = require('path');
3+
4+
/* == Globals == */
5+
var esDomain = {
6+
region: 'us-west-2',
7+
endpoint: 'http://ENDPOINT_HERE',
8+
index: 'messages',
9+
doctype: 'message'
10+
};
11+
var endpoint = new AWS.Endpoint(esDomain.endpoint);
12+
var creds = new AWS.EnvironmentCredentials('AWS');
13+
14+
15+
/* Lambda "main": Execution begins here */
16+
exports.handler = function(event, context) {
17+
18+
console.log(JSON.stringify(event, null, ' '));
19+
event.Records.forEach(function(record) {
20+
if (typeof record.dynamodb.NewImage != 'undefined')
21+
{
22+
var doc = {message: {
23+
name: record.dynamodb.NewImage.name.S,
24+
message: record.dynamodb.NewImage.message.S,
25+
channel: record.dynamodb.NewImage.channel.S,
26+
timestamp: record.dynamodb.NewImage.timestamp.N}
27+
}
28+
console.log('document posted to ElasticSearch: ' + JSON.stringify(doc))
29+
postToES(JSON.stringify(doc), context);
30+
}
31+
else
32+
{
33+
console.log('skipping non-inserts');
34+
}
35+
});
36+
}
37+
38+
39+
/*
40+
* Post the given document to Elasticsearch
41+
*/
42+
function postToES(doc, context) {
43+
var req = new AWS.HttpRequest(endpoint);
44+
45+
console.log('create post request');
46+
req.method = 'POST';
47+
req.path = path.join('/', esDomain.index, esDomain.doctype);
48+
req.region = esDomain.region;
49+
req.headers['presigned-expires'] = false;
50+
req.headers['Host'] = endpoint.host;
51+
req.body = doc;
52+
53+
console.log('Creating the Signer for the post request');
54+
var signer = new AWS.Signers.V4(req , 'es'); // es: service code
55+
signer.addAuthorization(creds, new Date());
56+
57+
console.log('Sending Data');
58+
var send = new AWS.NodeHttpClient();
59+
send.handleRequest(req, null, function(httpResp) {
60+
var respBody = '';
61+
httpResp.on('data', function (chunk) {
62+
respBody += chunk;
63+
});
64+
httpResp.on('end', function (chunk) {
65+
console.log('Response: ' + respBody);
66+
context.succeed('Lambda added document ' + doc);
67+
});
68+
}, function(err) {
69+
console.log('Error: ' + err);
70+
context.fail('Lambda failed with error ' + err);
71+
});
72+
}

Images/EdisonOverview.png

167 KB
Loading
164 KB
Loading

Images/MotionSensor-createTopic.png

79.5 KB
Loading
178 KB
Loading

Images/Search-Done.png

96 KB
Loading

Images/Search-Step20.png

72.6 KB
Loading

Images/Search-Step8.png

95.3 KB
Loading

Images/Slack-Step15.png

207 KB
Loading

0 commit comments

Comments
 (0)