Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 93 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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. πŸš€
8 changes: 8 additions & 0 deletions f.py
Original file line number Diff line number Diff line change
@@ -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'