-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathhandler.js
32 lines (24 loc) · 882 Bytes
/
handler.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
'use strict';
const AWS = require('aws-sdk');
const uuid = require('uuid');
module.exports.dataReceiver = (event, context, callback) => {
const data = event.data;
const kinesis = new AWS.Kinesis();
const partitionKey = uuid.v1();
const params = {
Data: data,
PartitionKey: partitionKey,
StreamName: 'data-receiver'
};
return kinesis.putRecord(params, (error, data) => {
if (error) {
callback(error);
}
callback(null, { message: 'Data successfully written to Kinesis stream "data-receiver"' });
});
};
module.exports.logger = (event, context, callback) => {
// print out the event information on the console (so that we can see it in the CloudWatch logs)
console.log(`The following data was written to the Kinesis stream "data-receiver":\n${JSON.stringify(event.Records[0].kinesis, null, 2)}`);
callback(null, { event });
};