packages feed

aws-lambda-haskell-runtime 3.0.0 → 3.0.1

raw patch · 3 files changed

+32/−11 lines, 3 files

Files

aws-lambda-haskell-runtime.cabal view
@@ -4,10 +4,10 @@ -- -- see: https://github.com/sol/hpack ----- hash: c21b3c988844f7c4bfb806aff4e307c5d5dc63a7973eff4a83eb329e7bccb1c9+-- hash: f12bd3188248690adb9f0c4972dd66cb983b9057555d14205384c600255cb999  name:           aws-lambda-haskell-runtime-version:        3.0.0+version:        3.0.1 synopsis:       Haskell runtime for AWS Lambda description:    Please see the README on GitHub at <https://github.com/theam/aws-lambda-haskell-runtime#readme> category:       AWS
src/Aws/Lambda/Runtime.hs view
@@ -1,3 +1,5 @@+{-# OPTIONS_GHC -fno-warn-name-shadowing #-}+ {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE TypeApplications    #-} @@ -35,10 +37,13 @@   manager <- Http.newManager httpManagerSettings   customContext <- initializeCustomContext   customContextRef <- newIORef customContext+  context   <- Context.initialize @context customContextRef `catch` errorParsing `catch` variableNotSet   forever $ do     lambdaApi <- Environment.apiEndpoint `catch` variableNotSet     event     <- ApiInfo.fetchEvent manager lambdaApi `catch` errorParsing-    context   <- Context.initialize @context customContextRef event `catch` errorParsing `catch` variableNotSet++    -- Purposefully shadowing to prevent using the initial "empty" context+    context <- Context.setEventData context event      (((invokeAndRun callback manager lambdaApi event context       `Checked.catch` \err -> Publish.parsingError err lambdaApi context manager)
src/Aws/Lambda/Runtime/Context.hs view
@@ -1,6 +1,7 @@ module Aws.Lambda.Runtime.Context   ( Context(..)   , initialize+  , setEventData   ) where  import Control.Exception.Safe.Checked@@ -29,25 +30,40 @@   :: Throws Error.Parsing   => Throws Error.EnvironmentVariableNotSet   => IORef context-  -> ApiInfo.Event   -> IO (Context context)-initialize customContextRef ApiInfo.Event{..} = do+initialize customContextRef = do   functionName          <- Environment.functionName   version               <- Environment.functionVersion   logStream             <- Environment.logStreamName   logGroup              <- Environment.logGroupName   memoryLimitInMb       <- Environment.functionMemory -  Environment.setXRayTrace traceId-  pure Context+  pure $ Context     { functionName       = functionName     , functionVersion    = version     , logStreamName      = logStream     , logGroupName       = logGroup     , memoryLimitInMb    = memoryLimitInMb-    , invokedFunctionArn = invokedFunctionArn-    , xrayTraceId        = traceId-    , awsRequestId       = awsRequestId-    , deadline           = deadlineMs     , customContext      = customContextRef++    -- We set those to "empty" values because they will be assigned+    -- from the incoming event once one has been received. (see setEventData)+    , invokedFunctionArn = mempty+    , xrayTraceId        = mempty+    , awsRequestId       = mempty+    , deadline           = 0     }++-- | Sets the context's event data+setEventData+  :: Context context+  -> ApiInfo.Event+  -> IO (Context context)+setEventData context ApiInfo.Event{..} = do+  Environment.setXRayTrace traceId++  return $ context+    { invokedFunctionArn = invokedFunctionArn+    , xrayTraceId        = traceId+    , awsRequestId       = awsRequestId+    , deadline           = deadlineMs }