Skip to content
This repository has been archived by the owner on Feb 14, 2024. It is now read-only.

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
iansu committed Jul 4, 2019
0 parents commit 272c0b6
Show file tree
Hide file tree
Showing 10 changed files with 634 additions and 0 deletions.
18 changes: 18 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# http://editorconfig.org
root = true

[*]
charset = utf-8
end_of_line = lf
indent_size = 2
indent_style = space
insert_final_newline = true
max_line_length = 100
trim_trailing_whitespace = true

[*.md]
max_line_length = 0
trim_trailing_whitespace = false

[COMMIT_EDITMSG]
max_line_length = 0
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
yarn.lock linguist-generated=true
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules

*.log
4 changes: 4 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"printWidth": 100,
"singleQuote": true
}
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## 1.0.0 (July 4, 2019)

Initial release! :tada:
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2019 Neo Financial Technologies Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Kinesis Logger

Read from the specified Kinesis stream and log messages to the console.

## Usage

```txt
kinesis-logger <name> [options]
read from the specified kinesis stream
Positionals:
name the name of the kinesis stream [string]
Options:
--version Show version number [boolean]
--region AWS region of kinesis stream
[string] [required] [default: "us-west-2"]
--offset number of seconds back in time to start reading from
[number] [required] [default: 0]
--help Show help [boolean]
```
48 changes: 48 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
const AWS = require('aws-sdk');
const { KinesisReadable } = require('kinesis-streams');
const { subSeconds } = require('date-fns');
const yargs = require('yargs');

const readStream = async args => {
const client = new AWS.Kinesis({ region: args.region, maxRetries: 10 });
const timestamp = subSeconds(new Date(), args.offset);
const reader = new KinesisReadable(client, args.name, {
logger: console,
parser: JSON.parse,
ShardIteratorType: 'AT_TIMESTAMP',
Timestamp: timestamp
});

reader.on('data', data => {
console.log(data);
});
};

yargs
.scriptName('kinesis-logger')
.usage('$0 name [args]')
.command({
command: '$0 <name> [options]',
describe: 'read from the specified kinesis stream',
builder: yargs =>
yargs.positional('name', {
demandOption: true,
describe: 'the name of the kinesis stream',
type: 'string'
}),
handler: readStream
})
.demandCommand(1)
.option('region', {
demandOption: true,
default: 'us-west-2',
describe: 'AWS region of kinesis stream',
type: 'string'
})
.option('offset', {
demandOption: true,
default: 0,
describe: 'number of seconds back in time to start reading from',
type: 'number'
})
.help().argv;
33 changes: 33 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"name": "kinesis-logger",
"description": "Read from the specified Kinesis stream and log messages to the console",
"version": "1.0.0",
"author": "Neo Financial Engineering <[email protected]>",
"main": "index.js",
"bin": "index.js",
"license": "MIT",
"homepage": "https://github.com/neofinancial/kinesis-logger",
"repository": {
"type": "git",
"url": "https://github.com/neofinancial/kinesis-logger"
},
"engines": {
"node": "^8.10.0"
},
"files": [
"index.js"
],
"keywords": [
"aws",
"kinesis",
"stream",
"javascript",
"node"
],
"dependencies": {
"aws-sdk": "^2.488.0",
"date-fns": "^1.30.1",
"kinesis-streams": "^0.12.0",
"yargs": "^13.2.4"
}
}
Loading

0 comments on commit 272c0b6

Please sign in to comment.