Skip to content

Commit d115a7e

Browse files
committedFeb 4, 2016
Merge pull request #2 from d-smith/kinesis-function
Added lambda function to write kinesis data to Sumo. NOTE: this function does not break up Kinesis messages like the Sumo Kinesis Connector.
2 parents bb19982 + c952f12 commit d115a7e

File tree

2 files changed

+88
-0
lines changed

2 files changed

+88
-0
lines changed
 

‎kinesis/README.md

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Kinesis to Sumologic
2+
3+
This function reads messages from a Kinesis
4+
stream and posts them to a SumoLogic hosted HTTP collector.
5+
6+
## Lambda configuration
7+
8+
There are no module dependencies for this code, so you can paste it into the
9+
lambda console directly. Note you must set the collector host and the
10+
path that includes your secret key in options for this to work.
11+
12+
For the Sumo collector configuration, do not enable multiline processing or
13+
one message per request -- the idea is to send as many messages in one request
14+
as possible to Sumo and let Sumo break them apart as needed.
15+
16+
In the AWS console, use a code entry type of 'Edit code inline' and paste in the
17+
code (doublecheck the hostname and path as per your collector setup).
18+
19+
In configuration specify index.handler as the Handler. Specify a Role that has
20+
sufficient privileges to read from the kinesis stream, invoke a lambda
21+
function, and write cloud watch logs. I tested with this policy, which is
22+
too loose for production.
23+
24+
<pre>
25+
{
26+
"Version": "2012-10-17",
27+
"Statement": [
28+
{
29+
"Effect": "Allow",
30+
"Action": [
31+
"lambda:InvokeFunction"
32+
],
33+
"Resource": [
34+
"*"
35+
]
36+
},
37+
{
38+
"Effect": "Allow",
39+
"Action": [
40+
"kinesis:GetRecords",
41+
"kinesis:GetShardIterator",
42+
"kinesis:DescribeStream",
43+
"kinesis:ListStreams",
44+
"logs:CreateLogGroup",
45+
"logs:CreateLogStream",
46+
"logs:PutLogEvents"
47+
],
48+
"Resource": "*"
49+
}
50+
]
51+
}
52+
</pre>
53+
54+
For the Event Source, pick the stream containing the data you want to send to Sumo.

‎kinesis/k2sl_lambda.js

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
var https = require('https');
2+
3+
///////////////////////////////////////////////////////////////////////////////////////////////////////////
4+
// Remember to change the hostname and path to match your collection API and specific HTTP-source endpoint
5+
// See more at: https://service.sumologic.com/help/Default.htm#Collector_Management_API.htm
6+
///////////////////////////////////////////////////////////////////////////////////////////////////////////
7+
var options = { 'hostname': 'endpoint1.collection.us2.sumologic.com',
8+
'path': 'https://endpoint1.collection.us2.sumologic.com/receiver/v1/http/XXXXX',
9+
'method': 'POST'
10+
};
11+
12+
exports.handler = function(event, context) {
13+
14+
var req = https.request(options, function(res) {
15+
var body = '';
16+
console.log('Status:', res.statusCode);
17+
res.setEncoding('utf8');
18+
res.on('data', function(chunk) { body += chunk; });
19+
res.on('end', function() {
20+
console.log('Successfully processed HTTPS response');
21+
context.succeed(); });
22+
});
23+
24+
options.agent = new https.Agent(options);
25+
26+
req.on('error', context.fail);
27+
28+
event.Records.forEach(function(record) {
29+
var payload = new Buffer(record.kinesis.data, 'base64').toString('ascii');
30+
req.write(payload + '\n');
31+
})
32+
req.end();
33+
34+
}

0 commit comments

Comments
 (0)
Please sign in to comment.