After we've spent a comical amount of time getting a Linux environment setup it's time to actually try to get Haskell running on aws lambda.
We’ve got our environment all set up so let’s get going!
Steps
stack new my-haskell-lambda https://github.com/theam/aws-lambda-haskell-runtime/raw/master/stack-template.hsfiles --resolver=lts-12.13 --omit-packages
Specifies which snapshot is to be used for this project. A snapshot defines a GHC version, a number of packages available for installation, and various settings like build flags. It is called a resolver since a snapshot states how dependencies are resolved. There are currently four resolver types:
extra-deps
flag commented out in the stack.yml
stack.yml
packages:
- .
extra-deps:
- aws-lambda-haskell-runtime-1.0.9
--omit-packages
I still needed to add packages .make
and we’re off to the races Progress 0/111
aws lambda create-function --function-name lambda-haskell \
--zip-file fileb://build/function.zip --handler src/Lib.handler \
--layers arn:aws:lambda:us-west-2:785355572843:layer:haskell-runtime:2 \
--runtime provided --role arn:aws:iam::XXXXXXXXXX:role/lambda-haskell-role
Can we update the code ?
aws lambda update-function-code --zip-file fileb://build/function.zip --publish --function-name lambda-haskell
HELL YES we can.
OK. So what did we actually deploy ? Let’s walk through the code.
Lib source file with aws runtime for having access to the ‘Context’ that is passed in to our application when it’s instantiated.
GHC.Generics for work with JSON
Aeson for (de)serializing JSON to our types
Handler
scr/Lib
handler
limit of Haskell runtimehandler :: Person -> Context -> IO (Either String Person)
Main
Person API *update age to a negative value or 0 and see the string response. Thanks great!
{
"personAge": 43,
"personName": "John Doe"
}
Runtime Details with Haskell Medium Post
Lexi Lambda Guide to Haskell 2018
JavaScript to Elm
Jesse Tomchak