1.0.0 • Published 5 years ago

kinesis-stream-lambda v1.0.0

Weekly downloads
2
License
MIT
Repository
github
Last release
5 years ago

kinesis-stream-lambda

NPM Version Node Build Status Coverage Status dependencies Status

Features

  • Easily reads a Lambda event of Kinesis Stream as a stream handling the chunk as Buffer
  • Supports KPL aggregation (set opts.isAgg true)
  • Provides KSL.parseJSON transform to handle items expanded array data in one record (set opts.flatArray true)
  • Node.js 6.10 or Later

How to install

$ npm install -save kinesis-stream-lambda

KPL aggregation only

furthermore,

$ npm install -save aws-kinesis-agg

Lambda handler examples

async/await style

const StreamUtils = require('@tilfin/stream-utils');
const KSL = require('kinesis-stream-lambda');
const PromisedLife = require('promised-lifestream');

exports.handler = async function (event) {
  console.log('event: ', JSON.stringify(event, null, 2));

  const result = [];

  await PromisedLife([
    KSL.reader(event, { isAgg: false }),
    KSL.parseJSON({ flatArray: false }),
    StreamUtils.map(function(data, cb) {
      result.push(data);
      cb(null, data)
    })
  ])

  console.dir(result);
}

normal style

const StreamUtils = require('@tilfin/stream-utils');
const KSL = require('kinesis-stream-lambda');

exports.handler = function (event, context, callback) {
  console.log('event: ', JSON.stringify(event, null, 2));

  const result = [];
  const stream = KSL.reader(event, { isAgg: false });

  stream.on('end', () => {
    console.dir(result);
    callback();
  });

  stream.on('error', err => {
    callback(err);
  });

  stream
  .pipe(KSL.parseJSON({ flatArray: false }))
  .pipe(StreamUtils.map(function(data, cb) {
    result.push(data);
    cb(null, data)
  }));
}

License

MIT

1.0.0

5 years ago

0.8.1

5 years ago

0.8.0

6 years ago

0.7.2

8 years ago

0.7.1

8 years ago

0.7.0

8 years ago

0.6.0

8 years ago

0.5.0

8 years ago

0.1.1

8 years ago

0.1.0

8 years ago