• Stars
    star
    149
  • Rank 248,619 (Top 5 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created about 11 years ago
  • Updated over 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A Node.js stream implementation of Amazon's Kinesis

kinesis

Build Status

A Node.js stream implementation of Amazon's Kinesis.

Allows the consumer to pump data directly into (and out of) a Kinesis stream.

This makes it trivial to setup Kinesis as a logging sink with Bunyan, or any other logging library.

For setting up a local Kinesis instance (eg for testing), check out Kinesalite.

NB: API has changed from 0.x to 1.x

Example

var fs = require('fs'),
    Transform = require('stream').Transform,
    kinesis = require('kinesis'),
    KinesisStream = kinesis.KinesisStream

// Uses credentials from process.env by default

kinesis.listStreams({region: 'us-west-1'}, function(err, streams) {
  if (err) throw err

  console.log(streams)
  // ["http-logs", "click-logs"]
})


var kinesisSink = kinesis.stream('http-logs')
// OR new KinesisStream('http-logs')

fs.createReadStream('http.log').pipe(kinesisSink)


var kinesisSource = kinesis.stream({name: 'click-logs', oldest: true})

// Data is retrieved as Record objects, so let's transform into Buffers
var bufferify = new Transform({objectMode: true})
bufferify._transform = function(record, encoding, cb) {
  cb(null, record.Data)
}

kinesisSource.pipe(bufferify).pipe(fs.createWriteStream('click.log'))


// Create a new Kinesis stream using the raw API
kinesis.request('CreateStream', {StreamName: 'test', ShardCount: 2}, function(err) {
  if (err) throw err

  kinesis.request('DescribeStream', {StreamName: 'test'}, function(err, data) {
    if (err) throw err

    console.dir(data)
  })
})

API

kinesis.stream(options)

new KinesisStream(options)

Returns a readable and writable Node.js stream for the given Kinesis stream

options include:

  • region: a string, or (deprecated) object with AWS credentials, host, port, etc (resolved from env or file by default)
  • credentials: an object with accessKeyId/secretAccessKey properties (resolved from env, file or IAM by default)
  • shards: an array of shard IDs, or shard objects. If not provided, these will be fetched and cached.
  • oldest: if truthy, then will start at the oldest records (using TRIM_HORIZON) instead of the latest
  • writeConcurrency: how many parallel writes to allow (1 by default)
  • cacheSize: number of PartitionKey-to-SequenceNumber mappings to cache (1000 by default)
  • agent: HTTP agent used (uses Node.js defaults otherwise)
  • timeout: HTTP request timeout (uses Node.js defaults otherwise)
  • initialRetryMs: first pause before retrying under the default policy (50 by default)
  • maxRetries: max number of retries under the default policy (10 by default)
  • errorCodes: array of Node.js error codes to retry on (['EADDRINFO', 'ETIMEDOUT', 'ECONNRESET', 'ESOCKETTIMEDOUT', 'ENOTFOUND', 'EMFILE'] by default)
  • errorNames: array of Kinesis exceptions to retry on (['ProvisionedThroughputExceededException', 'ThrottlingException'] by default)
  • retryPolicy: a function to implement a retry policy different from the default one

kinesis.listStreams([options], callback)

Calls the callback with an array of all stream names for the AWS account

kinesis.request(action, [data], [options], callback)

Makes a generic Kinesis request with the given action (eg, ListStreams) and data as the body.

options include:

  • region: a string, or (deprecated) object with AWS credentials, host, port, etc (resolved from env or file by default)
  • credentials: an object with accessKeyId/secretAccessKey properties (resolved from env, file or IAM by default)
  • agent: HTTP agent used (uses Node.js defaults otherwise)
  • timeout: HTTP request timeout (uses Node.js defaults otherwise)
  • initialRetryMs: first pause before retrying under the default policy (50 by default)
  • maxRetries: max number of retries under the default policy (10 by default)
  • errorCodes: array of Node.js error codes to retry on (['EADDRINFO', 'ETIMEDOUT', 'ECONNRESET', 'ESOCKETTIMEDOUT', 'ENOTFOUND', 'EMFILE'] by default)
  • errorNames: array of Kinesis exceptions to retry on (['ProvisionedThroughputExceededException', 'ThrottlingException'] by default)
  • retryPolicy: a function to implement a retry policy different from the default one

More Repositories

1

alpine-node

Minimal Node.js Docker Images built on Alpine Linux
Dockerfile
2,452
star
2

react-server-example

A simple example of how to do server-side rendering with React (no compilation needed)
JavaScript
1,792
star
3

kinesalite

An implementation of Amazon's Kinesis built on LevelDB
JavaScript
796
star
4

aws4

Signs and prepares Node.js requests using AWS Signature Version 4
JavaScript
663
star
5

aws4fetch

A compact AWS client for modern JS environments
JavaScript
405
star
6

react-server-routing-example

An example using universal client/server routing and data in React with AWS DynamoDB
JavaScript
299
star
7

simple-relay-starter

A very simple starter for React Relay using Browserify
JavaScript
156
star
8

epipebomb

Ignore EPIPE errors when stdout runs through a truncated pipe (such as `head`) in Node.js
JavaScript
63
star
9

awscred

Node.js module to resolve AWS credentials/region using env, ini files and IAM roles
JavaScript
45
star
10

gelf-stream

A node.js stream to send JS objects to a Graylog2 server (in GELF format)
JavaScript
28
star
11

StringStream

Encode and decode streams into string streams in node.js
JavaScript
27
star
12

dynamo-table

A lightweight module to map JS objects and queries to DynamoDB tables
JavaScript
24
star
13

gelfling

Create and send GELF (Graylog2) messages in node.js, including chunking
JavaScript
8
star
14

awslogger

A CLI tool to send lines from stdin to AWS CloudWatch Logs
JavaScript
7
star
15

aws2

Signs and prepares node.js http(s) requests using AWS Signature Version 2
JavaScript
6
star
16

deep_learning_glossary

Simple, opinionated explanations of various things encountered in Deep Learning
6
star
17

pdf2png-demo

A demo of Container Image Support in AWS Lambda
Go
6
star
18

test-ci-project

Shell
2
star
19

aws3

Signs and prepares node.js http(s) requests using AWS Signature Version 3
JavaScript
1
star