-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | A runtime environment for Haskell applications running on AWS Lambda. -- -- This library uniquely supports different types of AWS Lambda Handlers -- for your needs/comfort with advanced Haskell. Instead of exposing a -- single function that constructs a Lambda, this library exposes many. @package hal @version 0.1.5 module AWS.Lambda.Context data ClientApplication ClientApplication :: Text -> Text -> Text -> Text -> ClientApplication [appTitle] :: ClientApplication -> Text [appVersionName] :: ClientApplication -> Text [appVersionCode] :: ClientApplication -> Text [appPackageName] :: ClientApplication -> Text data ClientContext ClientContext :: ClientApplication -> Map Text Text -> Map Text Text -> ClientContext [client] :: ClientContext -> ClientApplication [custom] :: ClientContext -> Map Text Text [environment] :: ClientContext -> Map Text Text data CognitoIdentity CognitoIdentity :: Text -> Text -> CognitoIdentity [identityId] :: CognitoIdentity -> Text [identityPoolId] :: CognitoIdentity -> Text data LambdaContext LambdaContext :: Text -> Text -> Int -> Text -> Text -> Text -> Text -> Text -> UTCTime -> Maybe ClientContext -> Maybe CognitoIdentity -> LambdaContext [functionName] :: LambdaContext -> Text [functionVersion] :: LambdaContext -> Text [functionMemorySize] :: LambdaContext -> Int [logGroupName] :: LambdaContext -> Text [logStreamName] :: LambdaContext -> Text [awsRequestId] :: LambdaContext -> Text [invokedFunctionArn] :: LambdaContext -> Text [xRayTraceId] :: LambdaContext -> Text [deadline] :: LambdaContext -> UTCTime [clientContext] :: LambdaContext -> Maybe ClientContext [identity] :: LambdaContext -> Maybe CognitoIdentity class HasLambdaContext r withContext :: HasLambdaContext r => LambdaContext -> r -> r defConfig :: DefConfig a => a getRemainingTime :: MonadIO m => LambdaContext -> m DiffTime instance GHC.Generics.Generic AWS.Lambda.Context.LambdaContext instance GHC.Show.Show AWS.Lambda.Context.LambdaContext instance GHC.Generics.Generic AWS.Lambda.Context.CognitoIdentity instance GHC.Show.Show AWS.Lambda.Context.CognitoIdentity instance GHC.Generics.Generic AWS.Lambda.Context.ClientContext instance GHC.Show.Show AWS.Lambda.Context.ClientContext instance GHC.Generics.Generic AWS.Lambda.Context.ClientApplication instance GHC.Show.Show AWS.Lambda.Context.ClientApplication instance AWS.Lambda.Context.HasLambdaContext AWS.Lambda.Context.LambdaContext instance System.Envy.DefConfig AWS.Lambda.Context.LambdaContext instance Data.Aeson.Types.ToJSON.ToJSON AWS.Lambda.Context.CognitoIdentity instance Data.Aeson.Types.FromJSON.FromJSON AWS.Lambda.Context.CognitoIdentity instance Data.Aeson.Types.ToJSON.ToJSON AWS.Lambda.Context.ClientContext instance Data.Aeson.Types.FromJSON.FromJSON AWS.Lambda.Context.ClientContext instance Data.Aeson.Types.ToJSON.ToJSON AWS.Lambda.Context.ClientApplication instance Data.Aeson.Types.FromJSON.FromJSON AWS.Lambda.Context.ClientApplication module AWS.Lambda.Internal data StaticContext StaticContext :: Text -> Text -> Int -> Text -> Text -> StaticContext [functionName] :: StaticContext -> Text [functionVersion] :: StaticContext -> Text [functionMemorySize] :: StaticContext -> Int [logGroupName] :: StaticContext -> Text [logStreamName] :: StaticContext -> Text data DynamicContext DynamicContext :: Text -> Text -> Text -> UTCTime -> Maybe ClientContext -> Maybe CognitoIdentity -> DynamicContext [awsRequestId] :: DynamicContext -> Text [invokedFunctionArn] :: DynamicContext -> Text [xRayTraceId] :: DynamicContext -> Text [deadline] :: DynamicContext -> UTCTime [clientContext] :: DynamicContext -> Maybe ClientContext [identity] :: DynamicContext -> Maybe CognitoIdentity mkContext :: StaticContext -> DynamicContext -> LambdaContext instance GHC.Show.Show AWS.Lambda.Internal.DynamicContext instance GHC.Generics.Generic AWS.Lambda.Internal.StaticContext instance GHC.Show.Show AWS.Lambda.Internal.StaticContext instance System.Envy.DefConfig AWS.Lambda.Internal.StaticContext instance System.Envy.FromEnv AWS.Lambda.Internal.StaticContext module AWS.Lambda.RuntimeClient data RuntimeClientConfig getRuntimeClientConfig :: IO RuntimeClientConfig getNextEvent :: FromJSON a => RuntimeClientConfig -> IO (Response (Either JSONParseException a)) sendEventSuccess :: ToJSON a => RuntimeClientConfig -> ByteString -> a -> IO () sendEventError :: RuntimeClientConfig -> ByteString -> String -> IO () sendInitError :: RuntimeClientConfig -> String -> IO () instance GHC.Show.Show AWS.Lambda.RuntimeClient.JSONParseException instance GHC.Generics.Generic AWS.Lambda.RuntimeClient.LambdaError instance GHC.Show.Show AWS.Lambda.RuntimeClient.LambdaError instance GHC.Exception.Type.Exception AWS.Lambda.RuntimeClient.JSONParseException instance Data.Aeson.Types.ToJSON.ToJSON AWS.Lambda.RuntimeClient.LambdaError module AWS.Lambda.Runtime -- | For pure functions that can never fail. -- -- Use this for simple handlers that just translate input to output -- without side-effects. -- --
-- {-# LANGUAGE NamedFieldPuns, DeriveGeneric #-}
--
-- module Main where
--
-- import AWS.Lambda.Runtime (pureRuntime)
-- import Data.Aeson (FromJSON)
--
-- data Named = {
-- name :: String
-- } deriving Generic
-- instance FromJSON Named
--
-- myHandler :: Named -> String
-- myHandler Named { name } = "Hello, " ++ name ++ "!"
--
-- main :: IO ()
-- main = pureRuntime myHandler
--
pureRuntime :: (FromJSON event, ToJSON result) => (event -> result) -> IO ()
-- | For pure functions that can never fail that also need access to the
-- context.
--
-- Use this for simple handlers that just translate input to output
-- without side-effects, but that need the AWS Lambda Context as input.
--
--
-- {-# LANGUAGE NamedFieldPuns, DeriveGeneric #-}
--
-- module Main where
--
-- import AWS.Lambda.Context (LambdaContext(..))
-- import AWS.Lambda.Runtime (pureRuntimeWithContext)
-- import Data.Aeson (FromJSON)
-- import Data.Text (unpack)
--
-- data Named = {
-- name :: String
-- } deriving Generic
-- instance FromJSON Named
--
-- myHandler :: LambdaContext -> Named -> String
-- myHandler (LambdaContext { functionName }) (Named { name }) =
-- "Hello, " ++ name ++ " from " ++ unpack functionName ++ "!"
--
-- main :: IO ()
-- main = pureRuntimeWithContext myHandler
--
pureRuntimeWithContext :: (FromJSON event, ToJSON result) => (LambdaContext -> event -> result) -> IO ()
-- | For pure functions that can still fail.
--
-- Use this for simple handlers that just translate input to output
-- without side-effects, but can fail.
--
--
-- {-# LANGUAGE NamedFieldPuns, DeriveGeneric #-}
--
-- module Main where
--
-- import AWS.Lambda.Runtime (fallibleRuntime)
-- import Data.Aeson (FromJSON)
--
-- data Named = {
-- name :: String
-- } deriving Generic
-- instance FromJSON Named
--
-- myHandler :: Named -> Either String String
-- myHandler (Named { name }) =
-- if name == "World" then
-- Right "Hello, World!"
-- else
-- Left "Can only greet the world."
--
-- main :: IO ()
-- main = fallibleRuntime myHandler
--
fallibleRuntime :: (FromJSON event, ToJSON result) => (event -> Either String result) -> IO ()
-- | For pure functions that can still fail.
--
-- Use this for simple handlers that just translate input to output
-- without side-effects, but can fail and need the AWS Lambda Context as
-- input.
--
--
-- {-# LANGUAGE NamedFieldPuns, DeriveGeneric #-}
--
-- module Main where
--
-- import AWS.Lambda.Context (LambdaContext(..))
-- import AWS.Lambda.Runtime (fallibleRuntimeWithContext)
-- import Data.Aeson (FromJSON)
-- import Data.Text (unpack)
--
-- data Named = {
-- name :: String
-- } deriving Generic
-- instance FromJSON Named
--
-- myHandler :: LambdaContext -> Named -> Either String String
-- myHandler (LambdaContext { functionName }) (Named { name }) =
-- if name == "World" then
-- Right "Hello, World from " ++ unpack functionName ++ "!"
-- else
-- Left "Can only greet the world."
--
-- main :: IO ()
-- main = fallibleRuntimeWithContext myHandler
--
fallibleRuntimeWithContext :: (FromJSON event, ToJSON result) => (LambdaContext -> event -> Either String result) -> IO ()
-- | For functions with IO that can fail in a pure way (or via throw).
--
-- Use this for handlers that need any form of side-effect such as
-- reading environment variables or making network requests. However, do
-- not use this runtime if you need stateful (caching) behaviors.
--
--
-- {-# LANGUAGE NamedFieldPuns, DeriveGeneric #-}
--
-- module Main where
--
-- import AWS.Lambda.Runtime (ioRuntime)
-- import Data.Aeson (FromJSON)
-- import System.Environment (getEnv)
--
-- data Named = {
-- name :: String
-- } deriving Generic
-- instance FromJSON Named
--
-- myHandler :: Named -> IO String
-- myHandler (Named { name }) = do
-- greeting <- getEnv "GREETING"
-- return $ greeting ++ name
--
-- main :: IO ()
-- main = ioRuntime myHandler
--
ioRuntime :: (FromJSON event, ToJSON result) => (event -> IO (Either String result)) -> IO ()
-- | For functions with IO that can fail in a pure way (or via throw).
--
-- Use this for handlers that need any form of side-effect such as
-- reading environment variables or making network requests, and also
-- need the AWS Lambda Context as input. However, do not use this runtime
-- if you need stateful (caching) behaviors.
--
--
-- {-# LANGUAGE NamedFieldPuns, DeriveGeneric #-}
--
-- module Main where
--
-- import AWS.Lambda.Context (LambdaContext(..))
-- import AWS.Lambda.Runtime (ioRuntimeWithContext)
-- import Data.Aeson (FromJSON)
-- import Data.Text (unpack)
-- import System.Environment (getEnv)
--
-- data Named = {
-- name :: String
-- } deriving Generic
-- instance FromJSON Named
--
-- myHandler :: LambdaContext -> Named -> IO String
-- myHandler (LambdaContext { functionName }) (Named { name }) = do
-- greeting <- getEnv "GREETING"
-- return $ greeting ++ name ++ " from " ++ unpack functionName ++ "!"
--
-- main :: IO ()
-- main = ioRuntimeWithContext myHandler
--
ioRuntimeWithContext :: (FromJSON event, ToJSON result) => (LambdaContext -> event -> IO (Either String result)) -> IO ()
-- | For functions that can read the lambda context and use IO within the
-- same monad.
--
-- Use this for handlers that need any form of side-effect such as
-- reading environment variables or making network requests, and prefer
-- to access the AWS Lambda Context in the same monad. However, do not
-- use this runtime if you need stateful (caching) behaviors.
--
--
-- {-# LANGUAGE NamedFieldPuns, DeriveGeneric #-}
--
-- module Main where
--
-- import AWS.Lambda.Context (LambdaContext(..))
-- import AWS.Lambda.Runtime (readerTRuntime)
-- import Control.Monad.Reader (ReaderT, ask)
-- import Data.Aeson (FromJSON)
-- import Data.Text (unpack)
-- import System.Environment (getEnv)
--
-- data Named = {
-- name :: String
-- } deriving Generic
-- instance FromJSON Named
--
-- myHandler :: Named -> ReaderT LambdaContext IO String
-- myHandler Named { name } = do
-- LambdaContext { functionName } <- ask
-- greeting <- getEnv "GREETING"
-- return $ greeting ++ name ++ " from " ++ unpack functionName ++ "!"
--
-- main :: IO ()
-- main = readerTRuntime myHandler
--
readerTRuntime :: (FromJSON event, ToJSON result) => (event -> ReaderT LambdaContext IO result) -> IO ()
-- | For any monad that supports IOcatchReader LambdaContext.
--
-- Use this if you need caching behavours or are comfortable manipulating
-- monad transformers and want full control over your monadic interface.
--
--
-- {-# LANGUAGE NamedFieldPuns, DeriveGeneric #-}
--
-- module Main where
--
-- import AWS.Lambda.Context (LambdaContext(..))
-- import AWS.Lambda.Runtime (mRuntimeWithContext)
-- import Control.Monad.Reader (ReaderT, ask)
-- import Control.Monad.State.Lazy (StateT, runStateT, get, put)
-- import Data.Aeson (FromJSON)
-- import Data.Text (unpack)
-- import System.Environment (getEnv)
--
-- data Named = {
-- name :: String
-- } deriving Generic
-- instance FromJSON Named
--
-- myHandler :: Named -> StateT Int (ReaderT LambdaContext IO String)
-- myHandler Named { name } = do
-- LambdaContext { functionName } <- ask
-- greeting <- getEnv "GREETING"
--
-- greetingCount <- get
-- put $ greetingCount + 1
--
-- return $ greeting ++ name ++ " (" ++ show greetingCount ++ ") from " ++ unpack functionName ++ "!"
--
-- main :: IO ()
-- main = runStateT (mRuntimeWithContext myHandler) 0
--
mRuntimeWithContext :: (HasLambdaContext r, MonadCatch m, MonadReader r m, MonadIO m, FromJSON event, ToJSON result) => (event -> m result) -> m ()