Safe Haskell | None |
---|---|
Language | Haskell2010 |
The Infernal Machine - An AWS Lambda Custom Runtime for Haskell
See runLambda
or runSimpleLambda
for entrypoints to build your Lambda function.
Synopsis
- data CallbackConfig n = CallbackConfig {}
- type InitErrorCallback n = SomeException -> n LambdaError
- type InvokeErrorCallback n = LambdaRequest -> SomeException -> n LambdaError
- data LambdaError = LambdaError {
- _lerrErrorType :: !Text
- _lerrErrorMessage :: !Text
- newtype LambdaRequestId = LambdaRequestId {}
- data LambdaRequest = LambdaRequest {
- _lreqId :: !LambdaRequestId
- _lreqTraceId :: !Text
- _lreqFunctionArn :: !Text
- _lreqDeadlineMs :: !Int
- _lreqBody :: !ByteString
- data LambdaVars = LambdaVars {
- _lvLogGroupName :: !Text
- _lvLogStreamName :: !Text
- _lvFunctionVersion :: !Text
- _lvFunctionName :: !Text
- _lvTaskRoot :: !Text
- _lvApiEndpoint :: !Text
- _lvFunctionMemory :: !Text
- _lvHandlerName :: !Text
- type RunCallback n = LambdaRequest -> n ByteString
- type UncaughtErrorCallback n = SomeException -> n ()
- defaultCallbackConfig :: Applicative n => RunCallback n -> CallbackConfig n
- defaultLambdaError :: LambdaError
- defaultInitErrorCallback :: Applicative n => InitErrorCallback n
- runLambda :: (MonadCatch m, WithSimpleLog env m) => UnliftIO n -> InitErrorCallback n -> (LambdaVars -> n (CallbackConfig n)) -> m ()
- runSimpleLambda :: RunCallback (RIO App) -> IO ()
Documentation
data CallbackConfig n Source #
User callbacks to be invoked by the main loop (see runLambda
).
type InitErrorCallback n = SomeException -> n LambdaError Source #
Error mapper for init errors. The result will be POST
ed to the init 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 Source #
Error mapper for invocation errors. The result will be POST
ed to the invocation error endpoint (docs).
Exceptions of type LambdaError
will not trigger this callback, and ExitCode
will be rethrown after it executes.
data LambdaError Source #
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.
LambdaError | |
|
Instances
newtype LambdaRequestId Source #
The UUID associated with a Lambda request.
Instances
Eq LambdaRequestId Source # | |
Defined in Infernal (==) :: LambdaRequestId -> LambdaRequestId -> Bool # (/=) :: LambdaRequestId -> LambdaRequestId -> Bool # | |
Ord LambdaRequestId Source # | |
Defined in Infernal compare :: LambdaRequestId -> LambdaRequestId -> Ordering # (<) :: LambdaRequestId -> LambdaRequestId -> Bool # (<=) :: LambdaRequestId -> LambdaRequestId -> Bool # (>) :: LambdaRequestId -> LambdaRequestId -> Bool # (>=) :: LambdaRequestId -> LambdaRequestId -> Bool # max :: LambdaRequestId -> LambdaRequestId -> LambdaRequestId # min :: LambdaRequestId -> LambdaRequestId -> LambdaRequestId # | |
Show LambdaRequestId Source # | |
Defined in Infernal showsPrec :: Int -> LambdaRequestId -> ShowS # show :: LambdaRequestId -> String # showList :: [LambdaRequestId] -> ShowS # | |
IsString LambdaRequestId Source # | |
Defined in Infernal fromString :: String -> LambdaRequestId # | |
Hashable LambdaRequestId Source # | |
Defined in Infernal hashWithSalt :: Int -> LambdaRequestId -> Int # hash :: LambdaRequestId -> Int # |
data LambdaRequest Source #
The request parsed from the "next invocation" API (docs)
LambdaRequest | |
|
Instances
Eq LambdaRequest Source # | |
Defined in Infernal (==) :: LambdaRequest -> LambdaRequest -> Bool # (/=) :: LambdaRequest -> LambdaRequest -> Bool # | |
Show LambdaRequest Source # | |
Defined in Infernal showsPrec :: Int -> LambdaRequest -> ShowS # show :: LambdaRequest -> String # showList :: [LambdaRequest] -> ShowS # |
data LambdaVars Source #
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.
LambdaVars | |
|
type RunCallback n = LambdaRequest -> n ByteString Source #
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 UncaughtErrorCallback n = SomeException -> n () Source #
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.
defaultCallbackConfig :: Applicative n => RunCallback n -> CallbackConfig n Source #
A CallbackConfig
that returns defaultLambdaError
from all error callbacks.
defaultLambdaError :: LambdaError Source #
A LambdaError
that indicates a vague InternalError
to AWS.
defaultInitErrorCallback :: Applicative n => InitErrorCallback n Source #
A InitErrorCallback
that always returns defaultLambdaError
.
:: (MonadCatch m, WithSimpleLog env m) | |
=> UnliftIO n | Runs your monad |
-> InitErrorCallback n | Error mapper for the callback builder |
-> (LambdaVars -> n (CallbackConfig n)) | Callback builder. When possible, do init work here so the framework can propagate init errors to AWS. |
-> m () |
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.
runSimpleLambda :: RunCallback (RIO App) -> IO () Source #
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.