-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/
-- | The Infernal Machine - An AWS Lambda Custom Runtime for Haskell
--
-- Please see the README on GitHub at
-- https://github.com/ejconlon/infernal#readme
@package infernal
@version 0.2.0
-- | The Infernal Machine - An AWS Lambda Custom Runtime for Haskell
--
-- See runLambda or runSimpleLambda for entrypoints to
-- build your Lambda function.
module Infernal
-- | User callbacks to be invoked by the main loop (see runLambda).
data CallbackConfig n
CallbackConfig :: !RunCallback n -> !InvokeErrorCallback n -> !UncaughtErrorCallback n -> CallbackConfig n
-- | See RunCallback
[_cbcRunCallback] :: CallbackConfig n -> !RunCallback n
-- | See InvokeErrorCallback
[_cbcInvokeErrorCallback] :: CallbackConfig n -> !InvokeErrorCallback n
-- | See UncaughtErrorCallback
[_cbcUncaughtErrorCallback] :: CallbackConfig n -> !UncaughtErrorCallback n
-- | Error mapper for init errors. The result will be POSTed to
-- the init error endpoint (docs). Exceptions of type
-- LambdaError will not trigger this callback, and ExitCode
-- will be rethrown after it executes.
type InitErrorCallback n = SomeException -> n LambdaError
-- | Error mapper for invocation errors. The result will be POSTed
-- to the invocation error endpoint (docs). Exceptions of type
-- LambdaError will not trigger this callback, and ExitCode
-- will be rethrown after it executes.
type InvokeErrorCallback n = LambdaRequest -> SomeException -> n LambdaError
-- | An error formatted to propagate to AWS (docs). Note that this
-- is an Exception so you can throw it to short-circuit processing
-- and report useful information. If you throw anything else a
-- defaultLambdaError will be reported with no useful information.
data LambdaError
LambdaError :: !Text -> !Text -> LambdaError
-- | The type of error that occurred. In this library is is often
-- StartCase-formated.
[_lerrErrorType] :: LambdaError -> !Text
-- | A useful error message
[_lerrErrorMessage] :: LambdaError -> !Text
-- | The UUID associated with a Lambda request.
newtype LambdaRequestId
LambdaRequestId :: Text -> LambdaRequestId
[_unLambdaRequestId] :: LambdaRequestId -> Text
-- | The request parsed from the "next invocation" API (docs)
data LambdaRequest
LambdaRequest :: !LambdaRequestId -> !Text -> !Text -> !Int -> !ByteString -> LambdaRequest
-- | From the Lambda-Runtime-Aws-Request-Id header
[_lreqId] :: LambdaRequest -> !LambdaRequestId
-- | From the Lambda-Runtime-Trace-Id header
[_lreqTraceId] :: LambdaRequest -> !Text
-- | From the Lambda-Runtime-Invoked-Function-Arn header
[_lreqFunctionArn] :: LambdaRequest -> !Text
-- | From the Lambda-Runtime-Deadline-Ms header, an epoch deadline
-- in ms
[_lreqDeadlineMs] :: LambdaRequest -> !Int
-- | The unparsed request body. Typically you will decode this.
[_lreqBody] :: LambdaRequest -> !ByteString
-- | Environment variables set by AWS (docs). You may not need to
-- read any of these, but the implementation needs the API endpoint var
-- to handle requests.
data LambdaVars
LambdaVars :: !Text -> !Text -> !Text -> !Text -> !Text -> !Text -> !Text -> !Text -> LambdaVars
-- | From the AWS_LAMBDA_LOG_GROUP_NAME env var
[_lvLogGroupName] :: LambdaVars -> !Text
-- | From the AWS_LAMBDA_LOG_STREAM_NAME env var
[_lvLogStreamName] :: LambdaVars -> !Text
-- | From the AWS_LAMBDA_FUNCTION_VERSION env var
[_lvFunctionVersion] :: LambdaVars -> !Text
-- | From the AWS_LAMBDA_FUNCTION_NAME env var
[_lvFunctionName] :: LambdaVars -> !Text
-- | From the LAMBDA_TASK_ROOT env var
[_lvTaskRoot] :: LambdaVars -> !Text
-- | From the AWS_LAMBDA_RUNTIME_API env var
[_lvApiEndpoint] :: LambdaVars -> !Text
-- | From the AWS_LAMBDA_FUNCTION_MEMORY_SIZE env var
[_lvFunctionMemory] :: LambdaVars -> !Text
-- | From the _HANDLER env var
[_lvHandlerName] :: LambdaVars -> !Text
-- | The "function" part of your Lambda: takes a request with a
-- JSON-encoded body and returns a JSON-encoded response body. You can
-- throw any Exception and the appropriate error callbacks will
-- process it. Most importantly, LambdaError will propagate a
-- formatted error to AWS, and ExitCode will halt the program.
-- Except for ExitCode, throwing exceptions here will not
-- terminate the main loop (see runLambda). Note that the AWS
-- custom runtime loop implemented in this library is single-threaded (as
-- required - we must finish an invocation before fetching the next) but
-- you are free to spawn threads in your callback.
type RunCallback n = LambdaRequest -> n ByteString
-- | A handler for otherwise uncaught errors (like failures to fetch next
-- invocation). These happen outside context in which we can report them
-- to AWS, so there is no need to return a LambdaError. Exceptions
-- of type ExitCode will be rethrown after this callback executes.
type UncaughtErrorCallback n = SomeException -> n ()
-- | A CallbackConfig that returns defaultLambdaError from
-- all error callbacks.
defaultCallbackConfig :: Applicative n => RunCallback n -> CallbackConfig n
-- | A LambdaError that indicates a vague InternalError to
-- AWS.
defaultLambdaError :: LambdaError
-- | A InitErrorCallback that always returns
-- defaultLambdaError.
defaultInitErrorCallback :: Applicative n => InitErrorCallback n
-- | The full-powered entrypoint underlying runSimpleLambda that
-- allows you to use any UnliftIO-capable monad for your
-- callbacks. This runs the main loop of our AWS Lambda Custom Runtime to
-- fetch invocations, process them, and report errors or results. Control
-- will not return from this function, and AWS Lambda will terminate the
-- process at its will.
runLambda :: (MonadCatch m, WithSimpleLog env m) => UnliftIO n -> InitErrorCallback n -> (LambdaVars -> n (CallbackConfig n)) -> m ()
-- | A simple entrypoint that delegates to runLambda. Use this as
-- the body of your main function if you want to get a Lambda
-- function up and running quickly. All you need to do is provide a
-- RunCallback that handles JSON-encoded requests and returns
-- JSON-encoded responses (or throws LambdaError exceptions). Your
-- callback has access to a simple logger (try logDebug, for
-- example) whose output will be collected by Lambda and published to
-- CloudWatch.
runSimpleLambda :: RunCallback (RIO App) -> IO ()
instance Infernal.HasLambdaEnv Infernal.LambdaEnv
instance Heart.App.Logging.HasSimpleLog Infernal.LambdaEnv
instance GHC.Generics.Generic Infernal.LambdaError
instance GHC.Show.Show Infernal.LambdaError
instance GHC.Classes.Eq Infernal.LambdaError
instance GHC.Show.Show Infernal.LambdaRequest
instance GHC.Classes.Eq Infernal.LambdaRequest
instance Data.Hashable.Class.Hashable Infernal.LambdaRequestId
instance Data.String.IsString Infernal.LambdaRequestId
instance GHC.Classes.Ord Infernal.LambdaRequestId
instance GHC.Show.Show Infernal.LambdaRequestId
instance GHC.Classes.Eq Infernal.LambdaRequestId
instance GHC.Exception.Type.Exception Infernal.LambdaError
instance Data.Aeson.Types.ToJSON.ToJSON Infernal.LambdaError