https://github.com/lpil/purescript-aws-lambda-express
https://github.com/lpil/purescript-aws-lambda-express
Last synced: 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/lpil/purescript-aws-lambda-express
- Owner: lpil
- License: mpl-2.0
- Created: 2017-11-03T23:34:21.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2018-10-19T14:02:29.000Z (over 7 years ago)
- Last Synced: 2026-02-07T15:42:57.290Z (3 months ago)
- Language: PureScript
- Size: 15.6 KB
- Stars: 23
- Watchers: 2
- Forks: 5
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# purescript-aws-lambda-express
Catchy name, no?
This library make it easy to deploy a web app written with
[purescript-express][ps-express] to [AWS Lambda][aws-lambda], Amazon's
serverless compute service. Under the hood it uses Amazon's
[aws-serverless-express][aws-s-e].
[ps-express]: https://github.com/nkly/purescript-express
[aws-lambda]: https://aws.amazon.com/lambda
[aws-s-e]: https://github.com/awslabs/aws-serverless-express
## Show me how it works
```sh
bower install --save purescript-aws-lambda-express purescript-express
npm install --save aws-serverless-express express
```
```purescript
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?
- No infrastructure to manage or maintain.
- Scaling takes seconds and handled automatically.
- Pay per request, no money wasted on idle servers.
- AWS's free quota is enough for low traffic apps.
- Free monitoring and other goodies out the box.
## Why not?
- Dedicated servers may be cheaper for high traffic apps.
- With infrequent traffic [cold starts][cold-starts] can impact response time.
- Compiling native extensions can be fiddly.
- Any in-memory or on-filesystem state is ethereal and may be deleted between requests.
[cold-starts]: https://aws.amazon.com/blogs/compute/container-reuse-in-lambda/
## 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][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.
[serverless-framework]: https://serverless.com/framework
## 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/.