MyNixOS website logo
Description

Haskell Webapps on AWS Lambda.

!wai-lambda

Turn any wai webapp ( spock, servant, etc) into a handler for AWS Lambda and API Gateway requests.

Works with any Lambda environment (nodejs, python, etc). Find out more in the README.

WAI Lambda - Haskell Webapps on AWS Lambda

Hackage

This Haskell library turns any wai webapp (spock, servant, etc) into a handler for AWS Lambda and API Gateway requests.

{-# LANGUAGE OverloadedStrings #-}
import Network.Wai
import Network.HTTP.Types
import Network.Wai.Handler.Lambda (run)

app :: Application
app _ respond = do
    putStrLn "I've done some IO here"
    respond $ responseLBS
        status200
        [("Content-Type", "text/plain")]
        "Hello, Web!"

main :: IO ()
main = run app

This doesn't require any particular Lambda environment. By following the instructions in the build section the resulting zip file uploaded to AWS Lambda is typically smaller than 1MB. For basic webapps the request handling duration (as reported by AWS) is between 1 and 5 milliseconds.

Install

Cabal

Installing with Cabal:

$ cabal install wai-lambda

Stack

If you use stack and wai-lambda is not included in your snapshot, add it to the extra-deps:

extra-deps:
  - wai-lambda-0.1.0.0

or from GitHub:

packages:
- ...
- location:
    git: https://github.com/deckgo/wai-lambda.git
    commit: <some commit>
  extra-dep: true

Nix

You do not have to do anything if you use cabal2nix and a Nix commit that includes wai-lambda in its Hackage dependencies. If you want to use a specific commit of wai-lambda we recommend using niv:

$ niv add deckgo/wai-lambda

Then add an override to your Nix packages:


rec
{
    sources = import ./nix/sources.nix; # from niv
    pkgs = import sources.nixpkgs {};

    myHaskellPackages = pkgs.haskellPackages.override
        { overrides = self: super:
            { "wai-lambda" =
                super.callCabal2nix "wai-lambda" sources.wai-lambda;
            };
        };
}

See also the build section for producing AWS Lambda packages with nix.

Build

TODO

For inspiration on how to build fully static executables with Nix, see DeckDeckGo

Deploy

TODO

For inspiration on how to deploy with Terraform and Nix, see DeckDeckGo

License

MIT © David Dal Busco and Nicolas Mattia.

Metadata

Version

0.1.1.0

License

Executables (1)

  • bin/wai-lambda

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