Functions

Functions

Deploy functions: one TypeScript file run on Bun.

A function is one TypeScript file run by Bun, with no build step. Import npm packages by name (import { Hono } from "hono@4"); Bun installs them when the function starts. Read the port from process.env.PORT.

Without a schedule a function gets a URL, sleeps when idle and wakes on the next request. With a cron schedule it runs at those times and has no URL. Its logs and variables use the app commands: stackblaze logs -a <name>, stackblaze variables -a <name>.

stackblaze functions

Aliases: function, func, fn, fns

Functions live in a project environment (default production). list shows how each function runs (on request or on a schedule) and its URL. get shows how it runs, its URL and status; --code prints its file. deploy (alias new) creates a function, or updates an existing one's code, schedule or port; anything you do not pass is kept. invoke calls the function's URL and prints the answer; it exits 1 when the function answers an error or cannot be reached. delete asks you to type the name unless you pass -y.

usage
stackblaze functions list
stackblaze functions get <name> [--code]
stackblaze functions deploy <name> [-f <file>] [--schedule <cron> | --no-schedule] [--port <n>] [--wait]
stackblaze functions invoke <name> [--method <http>] [--body <text>] [--path <path>]
stackblaze functions delete <name> [-y]

Without --file, a new function starts from a "Hello" example, and an existing one keeps its code.

A scheduled function has no URL, so invoke refuses it.

FlagDescription
-f, --file <path>deploy: the TypeScript file to run (up to 96 KB)
--schedule <cron>deploy: run on a cron schedule (five fields) instead of on request
--no-scheduledeploy: run on request again (remove the schedule)
--port <n>deploy: port the function listens on (default 8080)
--waitdeploy: wait until the function is ready
--timeout <seconds>deploy: max time for --wait (default 300)
--name <name>deploy: same as the positional name
--codeget: print the function's TypeScript file
--method <http>invoke: HTTP method (default POST)
--body <text>invoke: request body
--path <path>invoke: path to call (default /)
-y, --yesSkip the confirmation prompt

Also accepts the scope flags (-p, --project, -e, --env, -a, --app) and the output flags (-o, --output, --json), plus --token, --api-url and --org. Common flags

Examples

terminal
stackblaze functions deploy hello --file index.ts --wait
stackblaze fn invoke hello --method GET
stackblaze functions deploy hello --file index.ts           # update the code
stackblaze functions deploy report --file report.ts --schedule "0 2 * * *"
stackblaze functions deploy report --no-schedule            # run on request again