-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | A modern and easy-to-use wrapper for Docker-based Lambda implementations -- -- Please see the README on GitHub at -- https://github.com/RobertFischer/hs-aws-lambda#readme @package hs-aws-lambda @version 0.1.0.2 module AWS.Lambda.RuntimeAPI.Types -- | Represents the data provided to an invocation of the lambda data LambdaInvocation payload LambdaInvocation :: Text -> Word64 -> Text -> Text -> Maybe MobileInvocationMetadata -> payload -> LambdaInvocation payload -- | The unique ID for this request [liAwsRequestId] :: LambdaInvocation payload -> Text -- | The timetsamp of the deadline in Unix time [liDeadlineMs] :: LambdaInvocation payload -> Word64 -- | This function's ARN [liInvokedFunctionArn] :: LambdaInvocation payload -> Text -- | The details about this AWS X-Ray trace [liTraceId] :: LambdaInvocation payload -> Text -- | The mobile data if the Lambda was called from the AWS Mobile SDK [liMobileMetadata] :: LambdaInvocation payload -> Maybe MobileInvocationMetadata -- | The input to the Lambda [liPayload] :: LambdaInvocation payload -> payload -- | The two possible results of a Lambda execution: success or failure data LambdaResult payload -- | Denotes success and provides the value to return LambdaSuccess :: payload -> LambdaResult payload -- | Denotes failure and provides details LambdaError :: ErrorInfo -> LambdaResult payload -- | Denotes that no invocation was provided LambdaNop :: LambdaResult payload data LambdaExecutionContext a m b LambdaExecutionContext :: String -> Manager -> (LambdaInvocation a -> m (LambdaResult b)) -> LambdaExecutionContext a m b [lecApiPrefix] :: LambdaExecutionContext a m b -> String [lecHttpManager] :: LambdaExecutionContext a m b -> Manager [lecHandler] :: LambdaExecutionContext a m b -> LambdaInvocation a -> m (LambdaResult b) -- | Additional information available only when the Lambda is invoked -- through the AWS Mobile SDK. This data is currently unstructured, but -- will be updated to be structured in some future major release. -- -- (Pull requests very welcome.) data MobileInvocationMetadata MobileInvocationMetadata :: Text -> Text -> MobileInvocationMetadata -- | the client's execution context [mimClientContext] :: MobileInvocationMetadata -> Text -- | the client's identity [mimCognitoIdentity] :: MobileInvocationMetadata -> Text -- | A space efficient, packed, unboxed Unicode text type. data Text -- | A class of types that can be fully evaluated. class NFData a -- | A class of functors that can be fully evaluated. class NFData1 (f :: Type -> Type) -- | A class for monads in which exceptions may be thrown. -- -- Instances should obey the following law: -- --
-- throwM e >> x = throwM e ---- -- In other words, throwing an exception short-circuits the rest of the -- monadic computation. class Monad m => MonadThrow (m :: Type -> Type) -- | Synchronously throw the given exception throw :: (MonadThrow m, Exception e) => e -> m a -- | Repeat an action indefinitely. -- -- Using ApplicativeDo: 'forever as' can be -- understood as the pseudo-do expression -- --
-- do as -- as -- .. ---- -- with as repeating. -- --
-- echoServer :: Socket -> IO () -- echoServer socket = forever $ do -- client <- accept socket -- forkFinally (echo client) (\_ -> hClose client) -- where -- echo :: Handle -> IO () -- echo client = forever $ -- hGetLine client >>= hPutStrLn client --forever :: Applicative f => f a -> f b -- | void value discards or ignores the result of -- evaluation, such as the return value of an IO action. -- -- Using ApplicativeDo: 'void as' can be -- understood as the do expression -- --
-- do as -- pure () ---- -- with an inferred Functor constraint. -- --
-- >>> void Nothing -- Nothing -- -- >>> void (Just 3) -- Just () ---- -- Replace the contents of an Either Int -- Int with unit, resulting in an Either -- Int (): -- --
-- >>> void (Left 8675309) -- Left 8675309 -- -- >>> void (Right 8675309) -- Right () ---- -- Replace every element of a list with unit: -- --
-- >>> void [1,2,3] -- [(),(),()] ---- -- Replace the second element of a pair with unit: -- --
-- >>> void (1,2) -- (1,()) ---- -- Discard the result of an IO action: -- --
-- >>> mapM print [1,2] -- 1 -- 2 -- [(),()] -- -- >>> void $ mapM print [1,2] -- 1 -- 2 --void :: Functor f => f a -> f () -- | A type that can be converted to JSON. -- -- Instances in general must specify toJSON and -- should (but don't need to) specify toEncoding. -- -- An example type and instance: -- --
-- -- Allow ourselves to write Text literals.
-- {-# LANGUAGE OverloadedStrings #-}
--
-- data Coord = Coord { x :: Double, y :: Double }
--
-- instance ToJSON Coord where
-- toJSON (Coord x y) = object ["x" .= x, "y" .= y]
--
-- toEncoding (Coord x y) = pairs ("x" .= x <> "y" .= y)
--
--
-- Instead of manually writing your ToJSON instance, there are two
-- options to do it automatically:
--
--
-- {-# LANGUAGE DeriveGeneric #-}
--
-- import GHC.Generics
--
-- data Coord = Coord { x :: Double, y :: Double } deriving Generic
--
-- instance ToJSON Coord where
-- toEncoding = genericToEncoding defaultOptions
--
--
-- If on the other hand you wish to customize the generic decoding, you
-- have to implement both methods:
--
--
-- customOptions = defaultOptions
-- { fieldLabelModifier = map toUpper
-- }
--
-- instance ToJSON Coord where
-- toJSON = genericToJSON customOptions
-- toEncoding = genericToEncoding customOptions
--
--
-- Previous versions of this library only had the toJSON method.
-- Adding toEncoding had two reasons:
--
--
-- {-# LANGUAGE DeriveGeneric #-}
--
-- import GHC.Generics
--
-- data Pair = Pair { pairFst :: a, pairSnd :: b } deriving Generic1
--
-- instance ToJSON a => ToJSON1 (Pair a)
--
--
-- If the default implementation doesn't give exactly the results you
-- want, you can customize the generic encoding with only a tiny amount
-- of effort, using genericLiftToJSON and
-- genericLiftToEncoding with your preferred Options:
--
--
-- customOptions = defaultOptions
-- { fieldLabelModifier = map toUpper
-- }
--
-- instance ToJSON a => ToJSON1 (Pair a) where
-- liftToJSON = genericLiftToJSON customOptions
-- liftToEncoding = genericLiftToEncoding customOptions
--
--
-- See also ToJSON.
class ToJSON1 (f :: Type -> Type)
-- | A type that can be converted from JSON, with the possibility of
-- failure.
--
-- In many cases, you can get the compiler to generate parsing code for
-- you (see below). To begin, let's cover writing an instance by hand.
--
-- There are various reasons a conversion could fail. For example, an
-- Object could be missing a required key, an Array could
-- be of the wrong size, or a value could be of an incompatible type.
--
-- The basic ways to signal a failed conversion are as follows:
--
--
-- -- Allow ourselves to write Text literals.
-- {-# LANGUAGE OverloadedStrings #-}
--
-- data Coord = Coord { x :: Double, y :: Double }
--
-- instance FromJSON Coord where
-- parseJSON (Object v) = Coord
-- <$> v .: "x"
-- <*> v .: "y"
--
-- -- We do not expect a non-Object value here.
-- -- We could use empty to fail, but typeMismatch
-- -- gives a much more informative error message.
-- parseJSON invalid =
-- prependFailure "parsing Coord failed, "
-- (typeMismatch "Object" invalid)
--
--
-- For this common case of only being concerned with a single type of
-- JSON value, the functions withObject, withScientific,
-- etc. are provided. Their use is to be preferred when possible, since
-- they are more terse. Using withObject, we can rewrite the above
-- instance (assuming the same language extension and data type) as:
--
-- -- instance FromJSON Coord where -- parseJSON = withObject "Coord" $ \v -> Coord -- <$> v .: "x" -- <*> v .: "y" ---- -- Instead of manually writing your FromJSON instance, there are -- two options to do it automatically: -- --
-- {-# LANGUAGE DeriveGeneric #-}
--
-- import GHC.Generics
--
-- data Coord = Coord { x :: Double, y :: Double } deriving Generic
--
-- instance FromJSON Coord
--
--
-- The default implementation will be equivalent to parseJSON =
-- genericParseJSON defaultOptions; if you need
-- different options, you can customize the generic decoding by defining:
--
--
-- customOptions = defaultOptions
-- { fieldLabelModifier = map toUpper
-- }
--
-- instance FromJSON Coord where
-- parseJSON = genericParseJSON customOptions
--
class FromJSON a
-- | Lifting of the FromJSON class to unary type constructors.
--
-- Instead of manually writing your FromJSON1 instance, there are
-- two options to do it automatically:
--
--
-- {-# LANGUAGE DeriveGeneric #-}
--
-- import GHC.Generics
--
-- data Pair a b = Pair { pairFst :: a, pairSnd :: b } deriving Generic1
--
-- instance FromJSON a => FromJSON1 (Pair a)
--
--
-- If the default implementation doesn't give exactly the results you
-- want, you can customize the generic decoding with only a tiny amount
-- of effort, using genericLiftParseJSON with your preferred
-- Options:
--
--
-- customOptions = defaultOptions
-- { fieldLabelModifier = map toUpper
-- }
--
-- instance FromJSON a => FromJSON1 (Pair a) where
-- liftParseJSON = genericLiftParseJSON customOptions
--
class FromJSON1 (f :: Type -> Type)
-- | Options that specify how to encode/decode your datatype to/from JSON.
--
-- Options can be set using record syntax on defaultOptions with
-- the fields below.
data Options
-- | & is a reverse application operator. This provides
-- notational convenience. Its precedence is one higher than that of the
-- forward application operator $, which allows & to be
-- nested in $.
--
-- -- >>> 5 & (+1) & show -- "6" --(&) :: a -> (a -> b) -> b infixl 1 & -- | Class for string-like datastructures; used by the overloaded string -- extension (-XOverloadedStrings in GHC). class IsString a fromString :: IsString a => String -> a -- | Observe a type representation for the type of a value. typeOf :: Typeable a => a -> TypeRep -- | 64-bit unsigned integer type data Word64 instance Control.DeepSeq.NFData AWS.Lambda.RuntimeAPI.Types.MobileInvocationMetadata instance GHC.Generics.Generic AWS.Lambda.RuntimeAPI.Types.MobileInvocationMetadata instance GHC.Classes.Eq AWS.Lambda.RuntimeAPI.Types.MobileInvocationMetadata instance GHC.Show.Show AWS.Lambda.RuntimeAPI.Types.MobileInvocationMetadata instance Data.Aeson.Types.FromJSON.FromJSON1 AWS.Lambda.RuntimeAPI.Types.LambdaInvocation instance Data.Aeson.Types.ToJSON.ToJSON1 AWS.Lambda.RuntimeAPI.Types.LambdaInvocation instance GHC.Generics.Generic1 AWS.Lambda.RuntimeAPI.Types.LambdaInvocation instance Data.Aeson.Types.FromJSON.FromJSON payload => Data.Aeson.Types.FromJSON.FromJSON (AWS.Lambda.RuntimeAPI.Types.LambdaInvocation payload) instance Data.Aeson.Types.ToJSON.ToJSON payload => Data.Aeson.Types.ToJSON.ToJSON (AWS.Lambda.RuntimeAPI.Types.LambdaInvocation payload) instance GHC.Generics.Generic (AWS.Lambda.RuntimeAPI.Types.LambdaInvocation payload) instance GHC.Classes.Eq payload => GHC.Classes.Eq (AWS.Lambda.RuntimeAPI.Types.LambdaInvocation payload) instance GHC.Show.Show payload => GHC.Show.Show (AWS.Lambda.RuntimeAPI.Types.LambdaInvocation payload) instance Data.Aeson.Types.FromJSON.FromJSON1 AWS.Lambda.RuntimeAPI.Types.LambdaResult instance Data.Aeson.Types.ToJSON.ToJSON1 AWS.Lambda.RuntimeAPI.Types.LambdaResult instance GHC.Generics.Generic1 AWS.Lambda.RuntimeAPI.Types.LambdaResult instance Data.Aeson.Types.FromJSON.FromJSON payload => Data.Aeson.Types.FromJSON.FromJSON (AWS.Lambda.RuntimeAPI.Types.LambdaResult payload) instance Data.Aeson.Types.ToJSON.ToJSON payload => Data.Aeson.Types.ToJSON.ToJSON (AWS.Lambda.RuntimeAPI.Types.LambdaResult payload) instance GHC.Generics.Generic (AWS.Lambda.RuntimeAPI.Types.LambdaResult payload) instance GHC.Classes.Eq payload => GHC.Classes.Eq (AWS.Lambda.RuntimeAPI.Types.LambdaResult payload) instance GHC.Show.Show payload => GHC.Show.Show (AWS.Lambda.RuntimeAPI.Types.LambdaResult payload) instance Control.DeepSeq.NFData payload => Control.DeepSeq.NFData (AWS.Lambda.RuntimeAPI.Types.LambdaResult payload) instance Control.DeepSeq.NFData1 AWS.Lambda.RuntimeAPI.Types.LambdaResult instance Control.DeepSeq.NFData payload => Control.DeepSeq.NFData (AWS.Lambda.RuntimeAPI.Types.LambdaInvocation payload) instance Control.DeepSeq.NFData1 AWS.Lambda.RuntimeAPI.Types.LambdaInvocation instance Data.Aeson.Types.ToJSON.ToJSON AWS.Lambda.RuntimeAPI.Types.MobileInvocationMetadata instance Data.Aeson.Types.FromJSON.FromJSON AWS.Lambda.RuntimeAPI.Types.MobileInvocationMetadata module AWS.Lambda.RuntimeAPI -- | This function is intended to be your main implementation. -- Given a handler for LambdaInvocation instances, it loops -- indefinitely (until AWS terminates the process) on the retrieval of -- invocations. It feeds each of those invocations into the handler that -- was passed in as an argument. It then posts the result back to AWS and -- begins the loop again. runLambda :: (MonadUnliftIO m, MonadFail m, MonadThrow m, FromJSON a, ToJSON b, NFData a, NFData b) => (LambdaInvocation a -> m (LambdaResult b)) -> m ()