Link Search Menu Expand Document

Avoid using the “Serverless Haskell” platform

After wading through some hand-wavy documentation and a questionable manifesto, my understanding is that “Serverless” is a tool which tries to provide a unified/common interface over various “cloud function” products (eg. AWS, Google Cloud, Microsoft Azure, etc.) [2] The marketing promise is that, you write your functions in one of the supported languages, add a sprinkling of configuration YML, and “Serverless” is going to figure out the plumbing required to deploy your functions on different cloud platforms.

With respect to Haskell, the serverless-haskell plugin does the following:

  1. compiles your Haskell code
  2. adds a NodeJS wrapper, because Haskell is NOT a first-class supported language in AWS Lambda, while NodeJS is.
    • it compiles your Haskell functions to a native binary
    • it autogenerates a wrapper script written in NodeJS, which is supported natively by AWS Lambda. All requests to your Lambda Function are first handled by this NodeJS wrapper script.
    • The wrapper-script calls the native binary and passes the incoming JSON payload as command-line arguments to the binary
    • The result from your function (which is now sitting inside the binary), is read from STDOUT and returned by the wrapper script.
  3. creates a Lambda Function in AWS (or updates an existing Function’s code)
  4. auto-configures API Gateway, CloudWatch, etc to complete the deployment

As of 2020, the NodeJS wrapper script is no longer required, because AWS Lambda now supports custom runtimes. In short, if your Lambda Function’s code contains a file called bootstrap, AWS Lambda will execute that file whenever your Lambda Function is invoked. It doesn’t matter what language your Lambda Function is written in, as long as it compiles down to a native Linux binary, called bootstrap.

Next, creating a Lambda Function is as easy as uploading a ZIP file (containing the Function’s code/assets) to AWS Lambda. And thanks to the amazonka-lambda library, we can do this in Haskell without depending upon a 3rd party tool.

Finally, we realised that we didn’t need API Gateway, and most probably even you don’t