forked from dherault/serverless-offline
/
InvocationsController.js
49 lines (39 loc) · 1.03 KB
/
InvocationsController.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
export default class InvocationsController {
#lambda = null
constructor(lambda) {
this.#lambda = lambda
}
async invoke(functionName, invocationType, event, clientContext) {
const lambdaFunction = this.#lambda.getByFunctionName(functionName)
lambdaFunction.setClientContext(clientContext)
lambdaFunction.setEvent(event)
if (invocationType === 'Event') {
// don't await result!
lambdaFunction.runHandler().catch((err) => {
// TODO handle error
console.log(err)
throw err
})
return {
Payload: '',
StatusCode: 202,
}
}
if (!invocationType || invocationType === 'RequestResponse') {
let result
try {
result = await lambdaFunction.runHandler()
} catch (err) {
// TODO handle error
console.log(err)
throw err
}
return result
}
// TODO FIXME
console.log(
`invocationType: '${invocationType}' not supported by serverless-offline`,
)
return undefined
}
}