diff --git a/README.md b/README.md new file mode 100644 index 0000000..3243dc9 --- /dev/null +++ b/README.md @@ -0,0 +1,93 @@ +# Hello, OpenLambda! 👋 + +This is the simplest possible [OpenLambda](https://github.com/open-lambda/open-lambda) +function — the "hello world" of serverless. If you've never written a serverless +function before, start here. + +## What is a lambda? + +A lambda is just a small function that runs on demand. You don't manage a server, +a `main()`, or a web framework — you write one function, and OpenLambda runs it +whenever someone calls it. + +The entire program is [`f.py`](f.py): + +```python +def f(event): + return 'hello' +``` + +The contract is tiny: + +- The function **must be named `f`**. +- It takes **one argument, `event`** — the data sent in the request. +- Whatever you **`return`** becomes the response (encoded as JSON). + +## Prerequisites + +You need a running OpenLambda worker. OpenLambda runs on **Linux (Ubuntu 24.04 LTS)**, +needs root privileges, and cgroups v2 — so on macOS/Windows use a Linux VM or container. + +Follow the [Getting Started guide](https://github.com/open-lambda/open-lambda/blob/main/docs/worker/getting-started.md) +to build and start a worker. The short version: + +```bash +make ol imgs/ol-min # build (Python-only) +./ol worker init -i ol-min +./ol worker up # starts the worker on localhost:5000 +``` + +## Run this function + +With a worker running, install this function straight from GitHub: + +```bash +./ol admin install https://github.com/open-lambda/hello-lambda-example.git +``` + +The function name is taken from the repo name, so invoke it like this: + +```bash +curl -X POST localhost:5000/run/hello-lambda-example -d '' +``` + +You should get back: + +``` +"hello" +``` + +🎉 You just ran your first serverless function. + +## Now change it + +Open [`f.py`](f.py) and make it greet you by name. The request body is passed in +as `event`, so you can read from it: + +```python +def f(event): + name = event.get('name', 'world') + return f'hello, {name}!' +``` + +Reinstall and call it again, this time sending some JSON: + +```bash +./ol admin install https://github.com/open-lambda/hello-lambda-example.git +curl -X POST localhost:5000/run/hello-lambda-example -d '{"name": "Ada"}' +``` + +→ `"hello, Ada!"` + +That's the whole loop: **edit `f.py` → install → curl**. + +## What's next? + +- Need a Python package? Add a `requirements.txt` next to `f.py` and OpenLambda + installs it for you. +- Browse the [`examples/`](https://github.com/open-lambda/open-lambda/tree/main/examples) + directory in the main repo — numpy, pandas, Flask, and more. +- Read the [worker docs](https://github.com/open-lambda/open-lambda/tree/main/docs/worker) + to learn how OpenLambda runs your code fast. + +Welcome to serverless. 🚀 diff --git a/f.py b/f.py index f048f47..d3cc3be 100644 --- a/f.py +++ b/f.py @@ -1,2 +1,10 @@ +# This is an OpenLambda function — a tiny serverless program. +# +# The whole contract is just this: +# * Define a function named `f`. +# * It takes ONE argument, `event` — the data sent in the request. +# * Whatever you `return` becomes the response (sent back as JSON). +# +# That's it. No servers to manage, no main(), no framework. def f(event): return 'hello'