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
cd mypackage npm init . npm install --save serverless email@example.com
The version of the NPM package to install must match the version of the Haskell package.
serverless.ymlwith the following contents:
service: myservice provider: name: aws runtime: haskell functions: myfunc: 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`. plugins: - serverless-haskell
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]
sls deployto deploy the executable 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.
This plugin supports handling API Gateway requests. Declare the HTTP events
serverless.yml and use
in the handler to process them.
Serverless Offline can be used for local testing of API Gateway requests.
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
v0.6.x. For anything else, target
Changes to the LTS branch will be forward ported to the
master branch after
- Haskell code is tested with Stack:
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,
- Get an AWS account and add the access credentials into your shell environment.
./integration-test/run.sh. The exit code indicates success.
- To verify just the packaging, without deployment, run
- By default, the integration test is run with LTS 12. To specify a different
- Ensure you are on a correct branch (
- Ensure that all the changes are reflected in the changelog.
- Run the integration tests.
./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.