@incdevco/framework
Version:
node.js lambda framework
57 lines (36 loc) • 1.02 kB
JavaScript
var AWS = require('aws-sdk');
function EventLog(config) {
'use strict';
config = config || {};
this.deliveryStreamName = config.name || 'event-log';
this.firehose = new AWS.Firehose();
}
EventLog.prototype.emit = function (name, data) {
'use strict';
return this.firehose.putRecord({
DeliveryStreamName: this.deliveryStreamName,
Record: this.eventToFirehoseRecord(name, data)
}).promise();
};
EventLog.prototype.emitBatch = function (events) {
'use strict';
var params = {
DeliveryStreamName: this.deliveryStreamName,
Records: []
};
var self = this;
events.forEach(function (event) {
params.Records.push(self.eventToFirehoseRecord(event.name, event.data));
});
return this.firehose.putRecordBatch(params).promise();
};
EventLog.prototype.eventToFirehoseRecord = function (name, data) {
'use strict';
return {
Data: JSON.stringify({
name: name,
data: data
})
};
};
module.exports = EventLog;