Last active
August 29, 2015 14:22
-
-
Save jrask/49e12284460400b4104d to your computer and use it in GitHub Desktop.
Adding a Transformer to get kinesis to work with bunyan
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var kinesis = require('kinesis') | |
var stream = require('stream') | |
var crypto = require('crypto') | |
// Make sure to set your AWS_PROFILE / AWS_DEFAULT_PROFILE unless you run IAM | |
var options = { | |
region: 'eu-west-1', | |
name: 'streamName' | |
} | |
var kinesisStream = kinesis.stream(options); | |
kinesisStream.on('error', function(error) { | |
throw error; | |
}); | |
// Must convert the data into an actual PutRecordRequest object | |
var asKinesisRecordWrapper = new stream.Transform({objectMode: true}) | |
asKinesisRecordWrapper._transform = function(chunk, encoding, cb) { | |
cb (null, { | |
Data : new Buffer(chunk).toString('base64'), | |
PartitionKey : crypto.randomBytes(16).toString('hex'), | |
StreamName : options.name | |
}); | |
}; | |
asKinesisRecordWrapper.pipe(kinesisStream) | |
var bunyan = require('bunyan'); | |
var logger = bunyan.createLogger({ | |
name: 'appName', | |
streams : [ | |
{ | |
stream: asKinesisRecordWrapper, | |
level: 'debug' | |
} | |
]} | |
); | |
logger.debug('Hello world!') | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment