Home

Awesome

purescript-aws-lambda-express

Catchy name, no?

This library make it easy to deploy a web app written with purescript-express to AWS Lambda, Amazon's serverless compute service. Under the hood it uses Amazon's aws-serverless-express.

Show me how it works

bower install --save purescript-aws-lambda-express purescript-express
npm install --save aws-serverless-express express
module Main where

import Node.Express.App (App, get)
import Node.Express.Handler (Handler)
import Node.Express.Response (sendJson)
import Network.AWS.Lambda.Express as Lambda

-- Define an Express web app

indexHandler :: Handler
indexHandler = do
  sendJson { status: "ok" }

app :: App
app = do
  get "/" indexHandler

-- Define the AWS Lambda handler

handler :: Lambda.HttpHandler
handler =
  Lambda.makeHandler app

Now compile the application for use within Node JS, zip it up, and upload it to AWS Lambda specifying Main.handler as the handler string.

FYI AWS Lambda really doesn't like directory names with .s in them and will throw a cryptic error, so best avoid a Purescript subdirectory. I lost an evening to this. 😓

Why deploy a web app this way?

Why not?

Is this ready for production?

I've used AWS Lambda for production workloads since 2016.

Or do you mean this library? Read the source, it's very small.

What's the easiest way to deploy code to AWS Lambda?

For automation of building zipping and uploading the application I have been using the Serverless Framework, which is friendlier than using the AWS API directly. This repository contains an example of it in use. See the Makefile and test/Main.purs for details.

LICENCE

Copyright © 2017 - present Louis Pilfold. All Rights Reserved.

This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.