GithubHelp home page GithubHelp logo

tarsbase / purescript-aws-lambda-express Goto Github PK

View Code? Open in Web Editor NEW

This project forked from lpil/purescript-aws-lambda-express

0.0 1.0 0.0 16 KB

License: Mozilla Public License 2.0

Makefile 25.74% JavaScript 13.80% PureScript 60.46%

purescript-aws-lambda-express's Introduction

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?

  • 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 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.

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/.

purescript-aws-lambda-express's People

Contributors

lpil avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.