Skip to content

Latest commit

 

History

History
93 lines (64 loc) · 2.57 KB

File metadata and controls

93 lines (64 loc) · 2.57 KB

Hello, OpenLambda! 👋

This is the simplest possible OpenLambda 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:

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 to build and start a worker. The short version:

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:

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

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 and make it greet you by name. The request body is passed in as event, so you can read from it:

def f(event):
    name = event.get('name', 'world')
    return f'hello, {name}!'

Reinstall and call it again, this time sending some JSON:

./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/ directory in the main repo — numpy, pandas, Flask, and more.
  • Read the worker docs to learn how OpenLambda runs your code fast.

Welcome to serverless. 🚀