| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Infernal
Description
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
- newtype LambdaResponse = LambdaResponse {}
- data LambdaVars = LambdaVars {
- _lvLogGroupName :: !Text
- _lvLogStreamName :: !Text
- _lvFunctionVersion :: !Text
- _lvFunctionName :: !Text
- _lvTaskRoot :: !Text
- _lvApiEndpoint :: !Text
- _lvFunctionMemory :: !Text
- _lvHandlerName :: !Text
- type RunCallback n = LambdaRequest -> n LambdaResponse
- type UncaughtErrorCallback n = SomeException -> n ()
- decodeRequest :: (MonadThrow m, FromJSON a) => LambdaRequest -> m a
- defaultCallbackConfig :: Applicative n => RunCallback n -> CallbackConfig n
- defaultLambdaError :: LambdaError
- defaultInitErrorCallback :: Applicative n => InitErrorCallback n
- encodeResponse :: ToJSON a => a -> LambdaResponse
- 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).
Constructors
| CallbackConfig | |
Fields | |
type InitErrorCallback n = SomeException -> n LambdaError Source #
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 InvokeErrorCallback n = LambdaRequest -> SomeException -> n LambdaError Source #
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.
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. By default, if you throw
anything else a defaultLambdaError will be reported with no useful information.
Constructors
| LambdaError | |
Fields
| |
Instances
newtype LambdaRequestId Source #
The UUID associated with a Lambda request.
Constructors
| LambdaRequestId | |
Fields | |
Instances
| Eq LambdaRequestId Source # | |
Defined in Infernal Methods (==) :: LambdaRequestId -> LambdaRequestId -> Bool # (/=) :: LambdaRequestId -> LambdaRequestId -> Bool # | |
| Ord LambdaRequestId Source # | |
Defined in Infernal Methods 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 Methods showsPrec :: Int -> LambdaRequestId -> ShowS # show :: LambdaRequestId -> String # showList :: [LambdaRequestId] -> ShowS # | |
| IsString LambdaRequestId Source # | |
Defined in Infernal Methods fromString :: String -> LambdaRequestId # | |
| Hashable LambdaRequestId Source # | |
Defined in Infernal | |
data LambdaRequest Source #
The request parsed from the "next invocation" API (docs)
Constructors
| LambdaRequest | |
Fields
| |
Instances
| Eq LambdaRequest Source # | |
Defined in Infernal Methods (==) :: LambdaRequest -> LambdaRequest -> Bool # (/=) :: LambdaRequest -> LambdaRequest -> Bool # | |
| Show LambdaRequest Source # | |
Defined in Infernal Methods showsPrec :: Int -> LambdaRequest -> ShowS # show :: LambdaRequest -> String # showList :: [LambdaRequest] -> ShowS # | |
newtype LambdaResponse Source #
A response to the LambdaRequest, typically as encoded JSON.
Constructors
| LambdaResponse | |
Fields | |
Instances
| Eq LambdaResponse Source # | |
Defined in Infernal Methods (==) :: LambdaResponse -> LambdaResponse -> Bool # (/=) :: LambdaResponse -> LambdaResponse -> Bool # | |
| Ord LambdaResponse Source # | |
Defined in Infernal Methods compare :: LambdaResponse -> LambdaResponse -> Ordering # (<) :: LambdaResponse -> LambdaResponse -> Bool # (<=) :: LambdaResponse -> LambdaResponse -> Bool # (>) :: LambdaResponse -> LambdaResponse -> Bool # (>=) :: LambdaResponse -> LambdaResponse -> Bool # max :: LambdaResponse -> LambdaResponse -> LambdaResponse # min :: LambdaResponse -> LambdaResponse -> LambdaResponse # | |
| Show LambdaResponse Source # | |
Defined in Infernal Methods showsPrec :: Int -> LambdaResponse -> ShowS # show :: LambdaResponse -> String # showList :: [LambdaResponse] -> ShowS # | |
| IsString LambdaResponse Source # | |
Defined in Infernal Methods fromString :: String -> LambdaResponse # | |
| Hashable LambdaResponse Source # | |
Defined in Infernal | |
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.
Constructors
| LambdaVars | |
Fields
| |
type RunCallback n = LambdaRequest -> n LambdaResponse 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.
decodeRequest :: (MonadThrow m, FromJSON a) => LambdaRequest -> m a Source #
Decodes a request with FromJSON or throws a LambdaError (BadRequestError).
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.
encodeResponse :: ToJSON a => a -> LambdaResponse Source #
Encodes a response with ToJSON. (Mostly here to save you an Aeson import.)
Arguments
| :: (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.