Functions
Serverless function deployment, invocation, and management
Overview
Scalix Functions let you deploy and invoke serverless functions with multiple runtime support. Functions scale to zero when idle. Warm invocations return in ~15ms; a cold start (full Firecracker microVM boot) takes ~1.6s.
Quick start
Create a function:
// handler.ts — the payload object is the FIRST ARGUMENT (handler mode)
export default async function handler(payload) {
return { result: payload.x + payload.y };
}Deploy:
scalix-cloud fn deploy add --source . --runtime node --handler handler.handlerfn deploy requires either --source <path> or --image <image>.
Invoke:
scalix-cloud fn invoke add --data '{"x": 1, "y": 2}'Handler contract (handler mode)
By default a function runs in handler mode, and the contract is deliberately minimal:
- The first argument is the invoke payload: the object you pass to
fn invoke(--data). Triggered invocations (cron, events) pass their trigger payload the same way. There is noRequestwrapper and noawait req.json(). - Return a value (or a promise). It is serialized as JSON into the invoke
response as
output, together with collectedlogsand anexit_code. - Errors bubble as invoke errors: a thrown exception fails the invocation with the exception message; a 2xx invoke means the handler returned.
// handler.ts (Node)
export default async function handler(payload) {
const total = (payload.items ?? []).reduce((sum, i) => sum + i.price, 0);
return { total, count: payload.items?.length ?? 0 };
}# handler.py (Python)
def handler(payload):
return {"echo": payload.get("message", "")}The entry point is module.function (default index.handler): set --handler
at deploy time, e.g. --handler src/main.process. HTTP-mode functions (deployed
with invocation_mode: http) run their own HTTP listener instead and are invoked
through their function URL; see the API reference for the deploy fields.
REST API
Deploy a function
curl -X POST https://api.scalix.world/v1/functions \
-H "Authorization: Bearer $SCALIX_API_KEY" \
-d '{
"name": "process-order",
"runtime": "node",
"image_ref": "api.scalix.world/<project-id>/process-order:latest",
"handler": "index.handler",
"timeout_ms": 30000,
"memory_mb": 256,
"env": { "STRIPE_KEY": "sk_..." }
}'Invoke a function
curl -X POST https://api.scalix.world/v1/functions/{id}/invoke \
-H "Authorization: Bearer $SCALIX_API_KEY" \
-d '{"order_id": "ord_123"}'List functions
scalix-cloud fn listView invocation logs
curl https://api.scalix.world/v1/functions/{id}/invocations \
-H "Authorization: Bearer $SCALIX_API_KEY"Supported runtimes
| Runtime | Value |
|---|---|
| Node.js | node |
| Python | python |
Scheduled functions
Deploy the function, then schedule it with a cron job that invokes it. Create the schedule with Cron:
# Deploy the function
scalix-cloud fn deploy daily-report --runtime node --source <git-url>
# Schedule it: <name> <cron-expression>, targeting the function
scalix-cloud cron create daily-report "0 6 * * *" \
--action-type function \
--config '{"function_id":"daily-report"}'Resource limits
| Setting | Default | Max |
|---|---|---|
| Timeout | 30s | 300s |
| Memory | 128 MB | 4 GB |
| vCPUs | 0.25 | 2 |
| Payload | 6 MB | 6 MB |