-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcount.js
63 lines (56 loc) · 1.74 KB
/
count.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
exports.command = 'count [bucket] [prefix]'
exports.describe = 'Count the events in [bucket] for [prefix]'
const _ = require('highland');
const lodash = require('lodash');
const now = require('moment')().utc();
exports.builder = {
bucket: {
alias: 'b',
describe: 'bucket containing the events'
},
stream: {
alias: 's',
describe: 'stream that delivered the events - root prefix'
},
prefix: {
alias: 'p',
default: `${now.format('YYYY')}/${now.format('MM')}/${now.format('DD')}/`
},
parallel: {
default: 16
},
region: {
alias: 'r',
default: process.env.AWS_REGION || 'us-east-1'
},
source: {
alias: 'sp',
description: 'source account profile',
default: process.env.AWS_PROFILE || 'default'
},
format: {
alias: 'f',
choices: [
'kinesis', // events wrapped in kinesis records
'eventbridge', // event wrapped in cloudwatch event format, delimited by EOL
'raw' // raw event format, delimited by EOL
],
default: 'kinesis' // original
}
}
exports.handler = (argv) => {
const common = require('../../lib/common')(argv);
common.print(argv);
common.s3.paginate()
.map(obj => common.s3.getEvents(obj))
.parallel(argv.parallel)
.reduce({}, (counters, cur) => {
counters.total = (counters.total ? counters.total : 0) + 1;
counters[cur.event.type] = (counters[cur.event.type] ? counters[cur.event.type] : 0) + 1;
return counters;
})
.tap(counters => console.log("Counters: %s", JSON.stringify(counters, null, 2)))
.errors(common.print)
.done(() => {})
;
}