Guide
From an empty folder to a function that answers on its own URL, runs on a schedule, and scales by itself. Every step is an HTTP call, so curl is all you need.
Before you start
Your platform operator gives you three things. Put them in your shell once:
export FAAS_API=https://api.faas.example # where you manage functions
export FAAS_URL=https://run.faas.example # where functions are called
export FAAS_TOKEN=EtEBCm... # your access token
The token acts for your tenant: the functions you create with it are yours, and nobody else can see them. You also need Node.js and npm where you write your code, and jq to read the answers below.
Write a function
A function is an ordinary HTTP server. It listens on the port the platform gives it, and that is the whole contract: no library to install, no handler signature to learn.
// index.js
const http = require('node:http')
http
.createServer((req, res) => {
console.log(req.method, req.url)
const name = new URL(req.url, 'http://function').searchParams.get('name') ?? 'world'
res.setHeader('content-type', 'application/json')
res.end(JSON.stringify({ message: `hello, ${name}` }))
})
.listen(process.env.PORT, () => console.log('listening'))
{ "name": "hello", "main": "index.js" }
Save the second file as package.json. Any framework that serves HTTP works the same way, such as Express, Fastify, or Hono, in CommonJS or as ES modules.
Deploy it
Create the function, then send its code as a tarball of the folder:
FUNCTION=$(curl -s -X POST "$FAAS_API/v1/functions" \
-H "Authorization: Bearer $FAAS_TOKEN" -H 'Content-Type: application/json' \
-d '{"name": "hello"}' | jq -r .id)
npm install --omit=dev
tar -czf ../hello.tar.gz .
curl -s -X PUT "$FAAS_API/v1/functions/$FUNCTION/code" \
-H "Authorization: Bearer $FAAS_TOKEN" -H 'Content-Type: application/gzip' \
--data-binary @../hello.tar.gz | jq '{status, revision}'
{ "status": "ready", "revision": 1 }
The call returns once the function is up, a few seconds later. Your dependencies travel in node_modules, inside the tarball. If the function fails to start, the answer quotes what it printed, so you see the stack trace without looking for logs.
Deploying again replaces the code and adds one to revision.
Call it
Your function has its own address. Everything after its identifier reaches it as the path of the request:
curl -i "$FAAS_URL/$FUNCTION/greet?name=you" -H "Authorization: Bearer $FAAS_TOKEN"
HTTP/1.1 200 OK
content-type: application/json
server-timing: restore;dur=98.4
{"message":"hello, you"}
Any method, any body, streamed both ways. The Server-Timing header appears when the request had to wake an instance, and says how many milliseconds that took. Later requests reuse the instance and don't carry it.
The platform answers by itself in a few cases, with a code your client can test:
| Status | Code | When |
|---|---|---|
| 401 | unauthenticated, token_expired |
The token is missing, invalid, or expired |
| 403 | forbidden |
The token doesn't allow calling this function |
| 404 | not_found |
Your tenant has no such function |
| 409 | not_deployed, deploy_failed |
The function has no code, or its last deploy failed |
| 429 | too_many_requests |
Every instance is busy: retry after the Retry-After delay |
| 502 | bad_gateway |
The function stopped before it answered |
| 503 | unavailable |
The function is being deployed: retry after the Retry-After delay |
| 504 | timeout |
The function didn't answer within its timeout_seconds |
To open a function to everyone, make it public: it is then called without a token.
curl -s -X PATCH "$FAAS_API/v1/functions/$FUNCTION" \
-H "Authorization: Bearer $FAAS_TOKEN" -H 'Content-Type: application/json' \
-d '{"public": true}'
Run it on a schedule
A trigger calls your function at the times of a cron expression, in the time zone you choose:
curl -s -X POST "$FAAS_API/v1/functions/$FUNCTION/triggers" \
-H "Authorization: Bearer $FAAS_TOKEN" -H 'Content-Type: application/json' \
-d '{"schedule": "0 8 * * 1-5", "timezone": "Europe/Paris"}' | jq '{id, next_fire_at}'
That one fires at 8:00 on weekdays. The function receives each occurrence as a CloudEvent, a POST / with the application/cloudevents+json content type:
{
"specversion": "1.0",
"id": "0d0a7c1e-8f1b-4b56-9d1c-5a4e3f2b1c0d",
"source": "/triggers/trigger_3f2b8c1e-6d4a-4f0b-9c57-0a1e2d3c4b5a",
"type": "com.github.davlgd.faas-ch.cron.fired",
"time": "2026-11-23T07:00:00Z",
"datacontenttype": "application/json",
"data": {
"trigger_id": "trigger_3f2b8c1e-6d4a-4f0b-9c57-0a1e2d3c4b5a",
"schedule": "0 8 * * 1-5",
"timezone": "Europe/Paris",
"scheduled_at": "2026-11-23T07:00:00Z"
}
}
Answer with a 2xx status and the run is recorded as succeeded; any other status records it as failed. The history of a trigger is one call away:
curl -s "$FAAS_API/v1/functions/$FUNCTION/triggers/$TRIGGER/runs" \
-H "Authorization: Bearer $FAAS_TOKEN" | jq '.items[] | {scheduled_at, outcome, http_status}'
A PATCH on the trigger changes its schedule or pauses it with "enabled": false.
Read its logs
What your function writes to its standard output and error is its log:
curl -s "$FAAS_API/v1/functions/$FUNCTION/logs?lines=50" -H "Authorization: Bearer $FAAS_TOKEN"
--- deploy boot, started 2026-11-22T18:11:23.207Z ---
listening
--- instance 1, started 2026-11-22T18:11:25.288Z ---
GET /greet?name=you
The log comes by instance, starting with the deploy, so you can tell what happened where.
Tune it
A function scales on its own: instances start when requests arrive, and stop when it goes quiet. These settings shape how, and you change any of them with a PATCH on the function:
| Setting | Default | Values | What it does |
|---|---|---|---|
idle_timeout_seconds |
60 |
1 to 3600 | Time an instance stays up without an invocation, in seconds. |
max_concurrency |
100 |
1 to 1000 | Most invocations one instance serves at once. |
max_instances |
2 |
1 to 64 | Most instances running at once. |
memory_mb |
256 |
128 to 4096 | Memory of an instance, in MiB. |
public |
false |
true or false | Whether the function can be invoked without a token. |
timeout_seconds |
60 |
1 to 3600 | Time an invocation may take, in seconds, from the request to the end of the |
curl -s -X PATCH "$FAAS_API/v1/functions/$FUNCTION" \
-H "Authorization: Bearer $FAAS_TOKEN" -H 'Content-Type: application/json' \
-d '{"max_instances": 8, "idle_timeout_seconds": 300}'
When every instance is busy and no more may start, callers get a 429 with a Retry-After header, so your function is never pushed past what you allowed.
Share access safely
Your token is a Biscuit. Whoever holds one can make a narrower copy of it, without asking the platform: for one function, for some operations, for a limited time.
faasd token --attenuate "$FAAS_TOKEN" \
--function "$FUNCTION" --operation function:invoke --expires-in 15m
That token can call one function for fifteen minutes, and nothing else. Give it to a webhook provider, a script, or a teammate, and your own token stays with you. A narrowed token can never be widened again.
| Operation | What it allows |
|---|---|
function:read |
See functions and their settings |
function:write |
Create, change, deploy, and delete functions |
function:invoke |
Call functions |
trigger:read |
See triggers and their runs |
trigger:write |
Create, change, and delete triggers |
logs:read |
Read the logs of functions |
How your function runs
Knowing three things about the life of a function lets you write faster and safer code.
It starts once, and every instance begins from there. When you deploy, the platform starts your function and keeps it as it was the moment it began to listen. Each new instance resumes from that point, with your modules loaded and your start-up work done. Put expensive preparation before listen, such as loading configuration or compiling templates: it runs once, not on every start.
What exists before listen is shared by all instances. That is what makes them fast, and it matters for anything that must differ between them. The platform refreshes Node.js's own random generators and the clock in each instance. For values of your own, and for libraries that prepare random values in advance, such as nanoid, use the fn:resume event, which fires once in every new instance:
let instanceId
process.on('fn:resume', () => {
instanceId = crypto.randomUUID()
})
Each instance has its own scratch space. The package is read-only, and /tmp is writable. /tmp is empty in a new instance and goes away with it, so keep what must last in a database or an object store.
When something fails
Every error is a JSON document with a code for your program and a detail written for you:
{
"status": 400,
"code": "invalid_request",
"detail": "`memory_mb` must be an integer between 128 and 4096"
}
The API reference lists every route, every setting, and every code.