aws-lambda-runtime-0.0.0.1: Haskell on AWS Lambda Runtime API

Safe HaskellNone
LanguageHaskell2010

AWS.Lambda.RuntimeAPI.Package

Contents

Description

Utility to package lambda

Example usage, you need to run it on AWS Linux (e.g. Docker, see Dockerfile) with GHC, cabal and cabal-plan available.

module Main (main) where

import AWS.Lambda.RuntimeAPI.Package (defaultConf, packageAwsLambda)
import Data.Char                     (isSpace)

import qualified Data.ByteString.Lazy as LBS
import qualified System.Process       as P

main :: IO ()
main = do
    -- Build the executable
    let exe = "example-lambda"
    P.callProcess "cabal" ["new-build", exe]

    -- Find the build artifact
    exePath <- trim <$> P.readProcess "cabal-plan" [ "list-bin", exe ] ""
    putStrLn $ "Packaging executable: " ++ exePath

    -- Package it
    zipFile <- packageAwsLambda defaultConf exePath
    LBS.writeFile "example-lambda.zip" zipFile
  where
    trim = dropWhile isSpace . reverse . dropWhile isSpace . reverse

Given such environment, we can build an example lambda function:

% docker run -ti --rm -v $(pwd):work -w work amazonlinux-with-ghc

% cabal new-update
% cabal new-build
% runghc package-example-lambda.hs

The resulting example-lambda.zip is ready to be uploaded!

Synopsis

Documentation

packageAwsLambda Source #

Arguments

:: Conf 
-> FilePath 
-> IO ByteString

Result is ZIP package

Package AWS Lambda executable.

data Conf Source #

Constructors

Conf 

Fields

Utilities

findExtraLibs Source #

Arguments

:: [String]

additional libs

-> FilePath

ELF file

-> IO [FilePath] 

Run ldd on given filepath, return .so files.