Infinitely Scalable

Native Reason Apps

on AWS Lambda & Zeit Now

Reason Conf US
October 8, 2019
@_anmonteiro

Our application code








What we write to deploy our code

Our application code







What we write to deploy our code




hinders experimentation

Our weekend

Can we do better?


  • What if we didn't have to worry about deployments
  • or servers?
  • or scaling?

"Serverless"

"Serverless" in a nutshell


  • Deploy code without thinking about servers
  • Abstract away deployment target
    • Where does how code run?
    • How many instances?
    • Heuristics for auto-scaling?

Strong focus on


application development


👍

Only pay for what you use



👍

Only a handful


languages supported


  • JavaScript (Node.js)
  • Golang
  • Java
  • Python
  • Ruby
  • C#
  • Powershell

Glaring ommission, anyone?


👎

Until Last November


👍👍👍

Lambda Runtime API


[...] a simple interface to use any programming language, or a specific language version, for developing your functions.

How does this work at all?

> "Just an HTTP API"

Recap

  1. Poll Lambda Runtime API for events
  2. Get event payload; 3. call function, get the result
  1. HTTP POST function result to the runtime API
  2. GOTO 1

How do I use it?


  • Consume aws-lambda-ocaml-runtime as a library
  • Write your Lambda function
  • Start the runtime

What's a Zeit Now?

  • AWS is like LEGO
  • Zeit's Now.sh builds on top of AWS (& others)
  • End-to-end integration
    • 1 URL / deployment (immutable deployments)
    • HTTP proxy + routing to your Lambda functions
    • Logging dashboard
    • Zero-config for some workloads

Equivalent AWS Setup

  1. Compute (e.g. EC2) for building deployment artifacts
  2. S3 + Cloudfront for storing & serving static assets
  3. API Gateway to expose Lambdas over HTTP / routing
  4. Cloudwatch for logging
  5. Manual Lambda deployments
  6. Homegrown CLI for coordinating all of this? Bash?   😷

Zeit wires everything together

"For each request of a Node.js Serverless Function, two objects, request and response, are passed to it. These objects are the standard HTTP request and response objects [...]"

Now.sh Wrapper Library


For aws-lambda-ocaml-runtime


  • Preserves same assumptions
  • "Just another HTTP request handler"

Demo Time

Here's what we're gonna do:


  1. Write a Lambda function
  2. Use GraphQL and graphql_ppx
  3. to query the GitHub API with OneGraph
  4. Over HTTP/2   😱
  5. Respond with some HTML

In Reason compiled to native code





Deployed to now.sh

Cool, show me some code

Limitations


  • No control over compute
  • Paradigm Shift (where are my connections?!)
  • Realtime apps (e.g. WebSockets)?
  • DB connections? Locality of my data?
  • Pay-per-100ms can get very expensive
  • OCaml custom runtime could be more deploy friendly

Is this thing ready?


How many people use it?

Go Grab it!


$ opam pin add lambda-runtime \
    git+https://github.com/anmonteiro/aws-lambda-ocaml-runtime

In Conclusion

  • Custom runtimes make it easier to run OCaml / Reason on AWS
  • I can leave those Lambdas deployed and not worry about it
  • Experiment!
  • Ship, and share!

What would you like to build?

Thanks!




@_anmonteiro