https://github.com/tilfin/kinesis-stream-lambda
Readable stream in Lambda for Kinesis Stream
https://github.com/tilfin/kinesis-stream-lambda
kinesis-stream kpl-aggregation lambda nodejs stream
Last synced: 11 months ago
JSON representation
Readable stream in Lambda for Kinesis Stream
- Host: GitHub
- URL: https://github.com/tilfin/kinesis-stream-lambda
- Owner: tilfin
- License: mit
- Created: 2016-09-04T15:48:11.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2018-11-28T15:25:31.000Z (over 7 years ago)
- Last Synced: 2025-07-11T06:11:57.097Z (11 months ago)
- Topics: kinesis-stream, kpl-aggregation, lambda, nodejs, stream
- Language: JavaScript
- Size: 32.2 KB
- Stars: 7
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
kinesis-stream-lambda
=====================
[![NPM Version][npm-image]][npm-url]
[]()
[](https://travis-ci.org/tilfin/kinesis-stream-lambda)
[](https://coveralls.io/github/tilfin/kinesis-stream-lambda?branch=master)
[](https://david-dm.org/tilfin/kinesis-stream-lambda)
## 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
```javascript
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
```javascript
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](LICENSE)
[npm-image]: https://img.shields.io/npm/v/kinesis-stream-lambda.svg
[npm-url]: https://npmjs.org/package/kinesis-stream-lambda