{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE UndecidableInstances #-}
module Aws.Lambda.Runtime.Common
( RunCallback,
LambdaResult (..),
LambdaError (..),
LambdaOptions (..),
ApiGatewayDispatcherOptions (..),
HandlerType (..),
HandlerName (..),
RawEventObject,
)
where
import Aws.Lambda.Runtime.ALB.Types
import Aws.Lambda.Runtime.APIGateway.Types
( ApiGatewayDispatcherOptions (..),
ApiGatewayResponse,
ApiGatewayResponseBody,
)
import Aws.Lambda.Runtime.Context (Context)
import Aws.Lambda.Runtime.StandaloneLambda.Types
( StandaloneLambdaResponseBody,
)
import qualified Data.ByteString.Lazy as Lazy
import Data.Hashable (Hashable)
import Data.Text (Text)
import GHC.Generics (Generic)
import Data.String (IsString)
type RunCallback (handlerType :: HandlerType) context =
LambdaOptions context -> IO (Either (LambdaError handlerType) (LambdaResult handlerType))
newtype HandlerName = HandlerName {HandlerName -> Text
unHandlerName :: Text}
deriving newtype (HandlerName -> HandlerName -> Bool
(HandlerName -> HandlerName -> Bool)
-> (HandlerName -> HandlerName -> Bool) -> Eq HandlerName
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: HandlerName -> HandlerName -> Bool
== :: HandlerName -> HandlerName -> Bool
$c/= :: HandlerName -> HandlerName -> Bool
/= :: HandlerName -> HandlerName -> Bool
Eq, Int -> HandlerName -> ShowS
[HandlerName] -> ShowS
HandlerName -> String
(Int -> HandlerName -> ShowS)
-> (HandlerName -> String)
-> ([HandlerName] -> ShowS)
-> Show HandlerName
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> HandlerName -> ShowS
showsPrec :: Int -> HandlerName -> ShowS
$cshow :: HandlerName -> String
show :: HandlerName -> String
$cshowList :: [HandlerName] -> ShowS
showList :: [HandlerName] -> ShowS
Show, ReadPrec [HandlerName]
ReadPrec HandlerName
Int -> ReadS HandlerName
ReadS [HandlerName]
(Int -> ReadS HandlerName)
-> ReadS [HandlerName]
-> ReadPrec HandlerName
-> ReadPrec [HandlerName]
-> Read HandlerName
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS HandlerName
readsPrec :: Int -> ReadS HandlerName
$creadList :: ReadS [HandlerName]
readList :: ReadS [HandlerName]
$creadPrec :: ReadPrec HandlerName
readPrec :: ReadPrec HandlerName
$creadListPrec :: ReadPrec [HandlerName]
readListPrec :: ReadPrec [HandlerName]
Read, Eq HandlerName
Eq HandlerName =>
(HandlerName -> HandlerName -> Ordering)
-> (HandlerName -> HandlerName -> Bool)
-> (HandlerName -> HandlerName -> Bool)
-> (HandlerName -> HandlerName -> Bool)
-> (HandlerName -> HandlerName -> Bool)
-> (HandlerName -> HandlerName -> HandlerName)
-> (HandlerName -> HandlerName -> HandlerName)
-> Ord HandlerName
HandlerName -> HandlerName -> Bool
HandlerName -> HandlerName -> Ordering
HandlerName -> HandlerName -> HandlerName
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: HandlerName -> HandlerName -> Ordering
compare :: HandlerName -> HandlerName -> Ordering
$c< :: HandlerName -> HandlerName -> Bool
< :: HandlerName -> HandlerName -> Bool
$c<= :: HandlerName -> HandlerName -> Bool
<= :: HandlerName -> HandlerName -> Bool
$c> :: HandlerName -> HandlerName -> Bool
> :: HandlerName -> HandlerName -> Bool
$c>= :: HandlerName -> HandlerName -> Bool
>= :: HandlerName -> HandlerName -> Bool
$cmax :: HandlerName -> HandlerName -> HandlerName
max :: HandlerName -> HandlerName -> HandlerName
$cmin :: HandlerName -> HandlerName -> HandlerName
min :: HandlerName -> HandlerName -> HandlerName
Ord, Eq HandlerName
Eq HandlerName =>
(Int -> HandlerName -> Int)
-> (HandlerName -> Int) -> Hashable HandlerName
Int -> HandlerName -> Int
HandlerName -> Int
forall a. Eq a => (Int -> a -> Int) -> (a -> Int) -> Hashable a
$chashWithSalt :: Int -> HandlerName -> Int
hashWithSalt :: Int -> HandlerName -> Int
$chash :: HandlerName -> Int
hash :: HandlerName -> Int
Hashable, String -> HandlerName
(String -> HandlerName) -> IsString HandlerName
forall a. (String -> a) -> IsString a
$cfromString :: String -> HandlerName
fromString :: String -> HandlerName
IsString)
data HandlerType
= StandaloneHandlerType
| APIGatewayHandlerType
| ALBHandlerType
data LambdaError (handlerType :: HandlerType) where
StandaloneLambdaError :: StandaloneLambdaResponseBody -> LambdaError 'StandaloneHandlerType
APIGatewayLambdaError :: ApiGatewayResponse ApiGatewayResponseBody -> LambdaError 'APIGatewayHandlerType
ALBLambdaError :: ALBResponse ALBResponseBody -> LambdaError 'ALBHandlerType
data LambdaResult (handlerType :: HandlerType) where
StandaloneLambdaResult :: StandaloneLambdaResponseBody -> LambdaResult 'StandaloneHandlerType
APIGatewayResult :: ApiGatewayResponse ApiGatewayResponseBody -> LambdaResult 'APIGatewayHandlerType
ALBResult :: ALBResponse ALBResponseBody -> LambdaResult 'ALBHandlerType
type RawEventObject = Lazy.ByteString
data LambdaOptions context = LambdaOptions
{ forall context. LambdaOptions context -> RawEventObject
eventObject :: !RawEventObject,
forall context. LambdaOptions context -> HandlerName
functionHandler :: !HandlerName,
forall context. LambdaOptions context -> Text
executionUuid :: !Text,
forall context. LambdaOptions context -> Context context
contextObject :: !(Context context)
}
deriving ((forall x. LambdaOptions context -> Rep (LambdaOptions context) x)
-> (forall x.
Rep (LambdaOptions context) x -> LambdaOptions context)
-> Generic (LambdaOptions context)
forall x. Rep (LambdaOptions context) x -> LambdaOptions context
forall x. LambdaOptions context -> Rep (LambdaOptions context) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall context x.
Rep (LambdaOptions context) x -> LambdaOptions context
forall context x.
LambdaOptions context -> Rep (LambdaOptions context) x
$cfrom :: forall context x.
LambdaOptions context -> Rep (LambdaOptions context) x
from :: forall x. LambdaOptions context -> Rep (LambdaOptions context) x
$cto :: forall context x.
Rep (LambdaOptions context) x -> LambdaOptions context
to :: forall x. Rep (LambdaOptions context) x -> LambdaOptions context
Generic)