LTS 9, 10 and 11 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
Create serverless.yml with the following contents:
service: myservice
provider:
name: aws
runtime: nodejs8.10
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
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. Note: sls deploy function is not supported yet.
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.