-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
44 lines (36 loc) · 838 Bytes
/
index.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
import {
initialize,
initializeFrom,
defaultOptions,
decryptEvent,
fromDynamodb,
toPromise,
} from 'aws-lambda-stream';
import RULES from './rules';
const OPTIONS = { ...defaultOptions };
const PIPELINES = {
...initializeFrom(RULES),
};
const { debug } = OPTIONS;
export class Handler {
constructor(options = OPTIONS) {
this.options = options;
}
handle(event, includeErrors = true) {
return initialize(PIPELINES, this.options)
.assemble(
fromDynamodb(event)
.through(decryptEvent({
...this.options,
})),
includeErrors,
);
}
}
export const handle = async (event, context, int = {}) => {
debug('event: %j', event);
debug('context: %j', context);
return new Handler({ ...OPTIONS, ...int })
.handle(event)
.through(toPromise);
};