-
Notifications
You must be signed in to change notification settings - Fork 20
/
app.js
29 lines (24 loc) · 815 Bytes
/
app.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
/*! Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: MIT-0
*/
exports.handler = async (event) => {
const output = event.records.map((record) => {
// Extract JSON record from base64 data
const buffer = Buffer.from(record.data, "base64").toString()
const jsonRecord = JSON.parse(buffer)
// Add calculated field
jsonRecord.output = ((jsonRecord.cadence + 35) * (jsonRecord.resistance + 65)) / 100
// Convert back to base64 + add a newline
const dataBuffer = Buffer.from(
JSON.stringify(jsonRecord) + "\n",
"utf8"
).toString("base64")
return {
recordId: record.recordId,
result: "Ok",
data: dataBuffer,
}
})
console.log(`{ recordsTotal: ${output.length} }`)
return { records: output }
};