UNPKG

@incdevco/framework

Version:
69 lines (37 loc) 1.1 kB
var Util = require('util'); var Base = require('../index'); function Lambda(config) { 'use strict'; Base.call(this, config); } Util.inherits(Lambda, Base); Lambda.prototype.handler = function (event, context) { 'use strict'; var count, promise, self = this; count = 0; promise = this.Promise.resolve(true); this.log('original-event', JSON.stringify(event, null, 2)); event.Records.forEach(function (record, index) { count++; promise = promise.then(function () { return self.handleRecord(event, record) .catch(function (exception) { exception.recordIndex = index; throw exception; }); }); }); promise .then(function () { context.succeed(count); }) .catch(function (exception) { context.fail(exception); }); }; Lambda.prototype.handleRecord = function (event, record) { 'use strict'; this.log('record', JSON.stringify(record)); return this.Promise.resolve(record); }; module.exports = Lambda;