MyNixOS website logo
Description

A modern and easy-to-use wrapper for Docker-based Lambda implementations. Now with API Gateway support!

The Library for Easily Writing Your Lambdas in Haskell

Historically, if you wanted to use Haskell to write your Lambdas, you had to use a custom runtime. However, AWS now allows you to use Docker images instead, which simplifies deployments and avoids some nasty problems.

This library provides the translation layer that you need in order to fully leverage Lambda. It is implemented in a classy way for maximum flexibility, even if it makes the type signatures a bit complicated. There is an example of an implementation in the example folder, including a demonstration of how to do deployment. Here's the simplest usage, adapted slightly from the example:


import AWS.Lambda.RuntimeAPI ( runLambda )
import AWS.Lambda.RuntimeAPI.Types ( LambdaResult(..), LambdaInvocation(..) )
import Data.Aeson ( encode, Value )
import qualified Data.ByteString.Lazy.Char8 as C8

-- Two lines of boilerplate
main :: IO ()
main = runLambda handler

-- Your implementation's code
handler :: LambdaInvocation Value -> IO (LambdaResult String)
handler request = do
	putStrLn . C8.unpack $ encode request
	return $ LambdaSuccess "This is the result payload"

The request payload is wrapped in a LambdaInvocation type, which provides access to the particular invocation that is being processed. In this case, we're treating the type as an Aeson Value, which represents any arbitrary JSON structure.

Your handler is responsible for consuming that request and producing a LambdaResult. A LambdaResult instance is usually either LambdaSuccess payload or LambdaError (Text, Text). In the case of LambdaSuccess, the payload defines the "result" of the Lambda, and will be transformed into JSON via the ToJSON typeclass. In the case of LambdaError, the payload is (ErrorType, ErrorMessage), which is passed to the Lambda Runtime API in order to give a meaningful error to the user. There is also LambdaNop which does nothing, but that's intended for internal use only.

All of this executes in the IO monad in the example above, but you can use any monad that implements MonadUnliftIO, MonadFail, and MonadThrow.

And that's pretty much it.

Metadata

Version

0.2.0.0

License

publicDomain

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows