-
Notifications
You must be signed in to change notification settings - Fork 1
/
lambda.fsx
31 lines (26 loc) · 933 Bytes
/
lambda.fsx
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
#r "node_modules/fable-core/Fable.Core.dll"
open Fable.Core
open Fable.Core.JsInterop
[<Pojo>]
type LambdaContext =
{
callbackWaitsForEmptyEventLoop : bool
logGroupName : string
logStreamName : string
functionName : string
memoryLimitInMB : string
functionVersion : string
invokeid : string
awsRequestId : string
}
type NativeHandler<'Request, 'Response> = System.Func<'Request, LambdaContext, (System.Func<exn option, 'Response option, unit>), unit>
type AsyncHandler<'Request, 'Response> = LambdaContext -> 'Request -> Async<'Response>
let handler (handler : AsyncHandler<'Request, 'Response>) : NativeHandler<'Request, 'Response> =
System.Func<_,_,_,_>(fun request context callback ->
async {
try
let! response = handler context request
callback.Invoke(None, Some response)
with ex ->
callback.Invoke(Some ex, None)
} |> Async.StartImmediate)