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
Can we do better?
- What if we didn't have to worry about deployments
- or servers?
- or scaling?
"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?
👎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?
Recap
- Poll Lambda Runtime API for events
- Get event payload; 3. call function, get the result
- HTTP POST function result to the runtime API
- 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
- Compute (e.g. EC2) for building deployment artifacts
- S3 + Cloudfront for storing & serving static assets
- API Gateway to expose Lambdas over HTTP / routing
- Cloudwatch for logging
- Manual Lambda deployments
- 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"
Here's what we're gonna do:
- Write a Lambda function
- Use GraphQL and
graphql_ppx - to query the GitHub API with OneGraph
- Over HTTP/2 😱
- Respond with some HTML
In Reason compiled to native code
Deployed to now.sh
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?