serverless-haskell: Deploying Haskell code onto AWS Lambda using Serverless

[ aws, cloud, library, mit, network ] [ Propose Tags ]

Utilities to help process the events from AWS Lambda when deployed with the serverless-haskell plugin.

[Skip to Readme]
Versions [faq] 0.0.0, 0.0.2, 0.0.3, 0.0.4, 0.0.6, 0.1.0, 0.2.0, 0.2.1, 0.3.0, 0.3.1, 0.4.0, 0.4.1, 0.4.2, 0.4.3, 0.5.0, 0.5.1, 0.5.2, 0.5.3, 0.6.0, 0.6.1, 0.6.2, 0.6.3, 0.6.4, 0.6.5, 0.6.6, 0.6.7, 0.7.0, 0.7.1, 0.7.2, 0.7.3, 0.7.4, 0.7.5, 0.8.1, 0.8.2, 0.8.3, 0.8.4, 0.8.5, 0.8.6, 0.8.7, 0.8.8, 0.8.10, 0.8.11, 0.9.0, 0.9.1, 0.9.3, 0.9.4, 0.10.0, 0.10.1, 0.10.2, 0.10.3, 0.10.4, 0.10.5, 0.11.2, 0.11.3, 0.12.0, 0.12.1
Dependencies aeson, aeson-casing, aeson-extra, amazonka-core, amazonka-kinesis, amazonka-s3, base (>=4.7 && <5), bytestring, case-insensitive, http-types, iproute, lens, text, time, unix, unordered-containers [details]
License MIT
Category AWS, Cloud, Network
Home page
Bug tracker
Source repo head: git clone
Uploaded by AlexeyKotlyarov at 2018-10-30T22:44:34Z
Distributions LTSHaskell:0.8.8, NixOS:0.12.1
Downloads 20392 total (101 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Hackage Matrix CI
Docs pending
Build status unknown [no reports yet]


  • AWSLambda
    • AWSLambda.Events
      • AWSLambda.Events.APIGateway
      • AWSLambda.Events.KinesisEvent
      • AWSLambda.Events.Records
      • AWSLambda.Events.S3Event
      • AWSLambda.Events.SNSEvent
    • AWSLambda.Handler
    • AWSLambda.Orphans
  • Data
    • Aeson
      • Data.Aeson.Alternative
      • Data.Aeson.Embedded
      • Data.Aeson.TextValue


Maintainer's Corner

For package maintainers and hackage trustees

Readme for serverless-haskell-0.8.1

[back to package description]

Serverless Haskell

Build status Hackage Stackage LTS Hackage dependencies npm

Deploying Haskell code onto AWS Lambda using Serverless.



  • Create a Stack package for your code:

    stack new mypackage

    LTS 9-12 are supported, older versions are likely to work too but untested.

  • Initialise a Serverless project inside the Stack package directory and install the serverless-haskell plugin:

    cd mypackage
    npm init .
    npm install --save serverless serverless-haskell@x.y.z

    The version of the NPM package to install must match the version of the Haskell package.

  • Create serverless.yml with the following contents:

    service: myservice
      name: aws
      runtime: haskell
        handler: mypackage.myfunc
        # Here, mypackage is the Haskell package name and myfunc is the executable
        # name as defined in the Cabal file. The handler field may be prefixed
        # with a path of the form `dir1/.../dirn`, relative to `serverless.yml`,
        # which points to the location where the Haskell package `mypackage` is
        # defined. This prefix is not needed when the Stack project is defined at
        # the same level as `serverless.yml`.
      - serverless-haskell
  • Write your main function:

    import qualified Data.Aeson as Aeson
    import AWSLambda
    main = lambdaMain handler
    handler :: Aeson.Value -> IO [Int]
    handler evt = do
      putStrLn "This should go to logs"
      print evt
      pure [1, 2, 3]
  • Use sls deploy to deploy the executable to AWS Lambda.

    The serverless-haskell plugin will build the package using Stack and upload it to AWS together with a JavaScript wrapper to pass the input and output from/to AWS Lambda.

    You can test the function and see the invocation results with sls invoke myfunc.

    To invoke the function locally, use sls invoke local -f myfunc.

API Gateway

This plugin supports handling API Gateway requests. Declare the HTTP events normally in serverless.yml and use AWSLambda.Events.APIGateway in the handler to process them.

Serverless Offline can be used for local testing of API Gateway requests.


  • Only AWS Lambda is supported at the moment. Other cloud providers would require different JavaScript wrappers to be implemented.

See AWSLambda for documentation, including additional options to control the deployment.


Currently, apart from the master branch, an v0.6.x branch is maintained with no breaking changes since 0.6.0, for inclusion into Stackage LTS 12. For bugfixes and new features that do not change the existing behavior, please target v0.6.x. For anything else, target master.

Changes to the LTS branch will be forward ported to the master branch after releasing.


  • Haskell code is tested with Stack: stack test.
  • JavaScript code is linted with eslint.

Integration tests

Integration test verifies that the project can build and deploy a complete function to AWS, and it runs with expected functionality.

Integration test is only automatically run up to deployment due to the need for an AWS account. To run manually:

  • Ensure you have the required dependencies: curl, jq, NPM, pwgen and Stack.
  • Get an AWS account and add the access credentials into your shell environment.
  • Run ./integration-test/ The exit code indicates success.
  • To verify just the packaging, without deployment, run ./integration-test/ --dry-run.
  • By default, the integration test is run with LTS 12. To specify a different series, use RESOLVER_SERIES=lts-9.


  • Ensure you are on a correct branch (v0.6.x or master).
  • Ensure that all the changes are reflected in the changelog.
  • Run the integration tests.
  • Run ./bumpversion major|minor|patch. This will increment the version number, update the changelog, create and push the Git tag and the branch.
  • If you have released an LTS version, merge the version branch into master, taking care of the conflicts around version numbers and changelog, and release the latest version as well.