-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaws-lambda-handler.sample.js
More file actions
37 lines (32 loc) · 974 Bytes
/
aws-lambda-handler.sample.js
File metadata and controls
37 lines (32 loc) · 974 Bytes
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
/**
* AWS Lambda-style handler sample.
*
* @author Admilson B. F. Cossa
* SPDX-License-Identifier: Apache-2.0
*
* Runs locally without AWS credentials while preserving the import and handler
* shape used by Node.js Lambda functions.
*/
import { work } from "../dist/index.js";
export async function handler(event) {
const records = event.records ?? [];
const output = await work(records)
.inParallel(4)
.onError("continue")
.do(async (record) => ({ id: record.id, bytes: record.body.length }));
return {
statusCode: output.errors.length === 0 ? 200 : 207,
body: JSON.stringify({
processed: output.results.length,
failed: output.errors.length,
bytes: output.results.reduce((sum, item) => sum + item.bytes, 0),
}),
};
}
const response = await handler({
records: [
{ id: "a", body: "hello" },
{ id: "b", body: "workit" },
],
});
console.log(JSON.stringify({ sample: "aws-lambda-handler", response }));