/
InvokeController.js
40 lines (31 loc) · 939 Bytes
/
InvokeController.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
import serverlessLog from '../../../../serverlessLog.js'
import { createUniqueId } from '../../../../utils/index.js'
export default class InvokeController {
constructor(lambda) {
this._lambda = lambda
}
async invoke(functionName, event) {
const lambdaFunction = this._lambda.get(functionName)
const requestId = createUniqueId()
lambdaFunction.setEvent(event)
lambdaFunction.setRequestId(requestId)
let result
try {
result = await lambdaFunction.runHandler()
const {
billedExecutionTimeInMillis,
executionTimeInMillis,
} = lambdaFunction
serverlessLog(
`(λ: ${functionName}) RequestId: ${requestId} Duration: ${executionTimeInMillis.toFixed(
2,
)} ms Billed Duration: ${billedExecutionTimeInMillis} ms`,
)
} catch (err) {
// TODO handle error
console.log(err)
throw err
}
return result
}
}