1
1
module Aws.Lambda.Runtime.Context
2
2
( Context (.. )
3
3
, initialize
4
+ , setEventData
4
5
) where
5
6
6
7
import Control.Exception.Safe.Checked
@@ -29,25 +30,40 @@ initialize
29
30
:: Throws Error. Parsing
30
31
=> Throws Error. EnvironmentVariableNotSet
31
32
=> IORef context
32
- -> ApiInfo. Event
33
33
-> IO (Context context )
34
- initialize customContextRef ApiInfo. Event { .. } = do
34
+ initialize customContextRef = do
35
35
functionName <- Environment. functionName
36
36
version <- Environment. functionVersion
37
37
logStream <- Environment. logStreamName
38
38
logGroup <- Environment. logGroupName
39
39
memoryLimitInMb <- Environment. functionMemory
40
40
41
- Environment. setXRayTrace traceId
42
- pure Context
41
+ pure $ Context
43
42
{ functionName = functionName
44
43
, functionVersion = version
45
44
, logStreamName = logStream
46
45
, logGroupName = logGroup
47
46
, memoryLimitInMb = memoryLimitInMb
48
- , invokedFunctionArn = invokedFunctionArn
49
- , xrayTraceId = traceId
50
- , awsRequestId = awsRequestId
51
- , deadline = deadlineMs
52
47
, customContext = customContextRef
48
+
49
+ -- We set those to "empty" values because they will be assigned
50
+ -- from the incoming event once one has been received. (see setEventData)
51
+ , invokedFunctionArn = mempty
52
+ , xrayTraceId = mempty
53
+ , awsRequestId = mempty
54
+ , deadline = 0
53
55
}
56
+
57
+ -- | Sets the context's event data
58
+ setEventData
59
+ :: Context context
60
+ -> ApiInfo. Event
61
+ -> IO (Context context )
62
+ setEventData context ApiInfo. Event {.. } = do
63
+ Environment. setXRayTrace traceId
64
+
65
+ return $ context
66
+ { invokedFunctionArn = invokedFunctionArn
67
+ , xrayTraceId = traceId
68
+ , awsRequestId = awsRequestId
69
+ , deadline = deadlineMs }
0 commit comments