Lambdazonka
This is a project skeleton to show that all of the Haskell Amazonka AWS API libraries compile with GHCJS and could be deployed to AWS Lambda.
*NOTE: It’s been discovered that Amazonka uses the haskell network library. This library hasn’t been fully shimmed for GHCJS yet. So this whole thing will have to wait for a bit. :(*
Basic Dependencies
- Node.js Stable 0.10.x - AWS Lambda is currently 0.10.36. Don’t get aggressive with Node.js 4.x and 5.x from Nodesource. It’s not necessary and you might run into trouble.
- Haskell Stack - Install the latest for your OS and then run stack setup in your $HOME. This will give you a default GHC installation inside the $HOME/.stack directory.
- Additional Packages - You’ll need some basic developer packages
before bootstrapping GHCJS. Here’s an example on Ubuntu/Debian
apt-get install -y build-essential libtinfo-dev stack setup
Stack Setup (specific to GHCJS)
In this project directory and with Stack & Node.js in your PATH run the following:
stack setup
This will bootstrap GHCJS into your $HOME/.stack directory.
Building the GHCJS Project
The hsc2hs binary is required to be in your PATH in order to build Amazonka on GHCJS (or any time you need to rebuild Amazonka). I tried using an alias for *hsc2hs-ghcjs*, installed by Stack as part of GHCJS, but it didn’t work. You have a native hsc2hs in your $HOME that was installed in the stack setup step above. This works. Once the dependencies have been built you no longer need the special PATH.
export PATH=$HOME/.stack/programs/x86_64-linux/ghc-7.10.3/bin:$PATH
Now lets build the project (takes a while)
stack build
NOTE: Don’t worry too much about the Stack warnings that are shown about the version of GHCJS-compiled packages that are installed vs the Stackage LTS approved versions. This is a known issue to both Stack & GHCJS folks. Hopefully, as people have time for the effort, GHCJS will be 100% compatible with the Stackage LTS index. In my opinion, people survived for decades before Stackage was available. In my 2 full-time months on GHCJS using Stack, I haven’t seen any bugs that have kept my code from working. Be aware of these warnings though if something fishy comes up.
The “executable” (the js files) will be in your .stack-work directory in the project. The easy way to find them is to run:
find . -type d -name lambdazonka.jsexe
That’s it. The all.js file is self-contained and is all you need with Node.js or for deployment to the cloud. Now you are ready for AWS Lambda experiments!