th functions

Deploy Function ພາສາ Python, Node.js (TypeScript) ແລະ Go ຈາກໂຟນເດີ ດຶງໂຄ້ດທີ່ແກ້ໃນ Console ລົງເຄື່ອງ ແລະ ເອີ້ນໃຊ້ງານ

ກ່ຽວກັບ

A function is one handler: you write it, and we add a small runtime that serves it over HTTP, build it and run it like a Container that stops when idle. The same code shows in the Console’s editor, so you can edit it there or locally: th functions pull fetches what the Console saved and th functions deploy sends your folder back.

RuntimesMain fileHandler
python314, python313 (recommended), python312, python311main.py (+ requirements.txt)def main(request) returning a str, dict (JSON) or (body, status, headers)
nodejs24 (recommended), nodejs22index.ts or index.js (+ package.json)export async function handler(req: Request) returning a Response, string or object
go126 (recommended), go125*.go + go.modfunc Handle(w http.ResponseWriter, r *http.Request)

A function has at most 100 text files, 512 KiB each and 2 MiB in all. Files in .thignore (else .dockerignore, else .gitignore), .git, node_modules, .venv, __pycache__ and dist are left out, and a Dockerfile is ignored. Builds are billed like Container builds. To run it on a schedule or for every queue message, add a trigger with th triggers.

ວິທີເຮັດ

Deploy a function from a folder

Shell
mkdir hello && cd hello
printf 'def main(request):\n    return {"message": "Hello, " + request.args.get("name", "World")}\n' > main.py
th functions deploy hello --env GREETING=hi
th functions call hello --path "/?name=Thai"

The first deploy creates the function; its runtime comes from the files (or --runtime). th waits for the build and prints the URL. --async returns once the build is queued.

Go back to an earlier version

Shell
th functions versions list hello
th functions versions activate hello 12
th functions pull hello --version 12 --dir hello-v12

Every deploy is a version, and the latest 30 are kept. Activating one serves it again with today’s settings and variables; if its image was cleaned up, its code is built again as a new version. --runtime on a deploy moves the function to another version of its language, e.g. --runtime python314.

Run a function only from its triggers

Shell
th functions deploy nightly-report --ingress triggers
th triggers create nightly --service nightly-report --schedule "0 3 * * *"

With --ingress triggers the function has no endpoint at all: no public URL, no custom domain and no address inside the project’s VPC. Only its Cron and Queue triggers reach it, and th triggers run runs one now. --ingress all opens it again.

Edit in the Console, then work locally

Shell
th functions pull hello --dir hello
# edit the files
th functions deploy hello --source hello

pull keeps local files that differ unless you pass --force.

ຄຳສັ່ງ

ຄຳສັ່ງຄຳອະທິບາຍ
th functions deployUploads the files of DIR (default .) as the function's code, builds them and serves the result.
th functions listLists the functions of the active Project.
th functions describeShows a function's runtime, deploy state, settings and files.
th functions pullWrites the function's saved code (what the Console editor shows), or the code of one version, into DIR (default ./NAME).
th functions callSends one request to the function and prints the answer.
th functions logsPrints the latest log lines of a function (what the handler printed).
th functions versions listLists a function's versions, newest first.
th functions versions activateServes an earlier version again; today's settings and variables stay.
th functions runtimesLists the runtimes a function can use and the handler each expects.
th functions deleteDeletes a function with its code, triggers and revisions.

th functions deploy

Uploads the files of DIR (default .) as the function's code, builds them and serves the result.

ຮູບແບບຄຳສັ່ງ

Shell
th functions deploy NAME [--source DIR] [flags]

A new function is created first; its runtime comes from --runtime or from the files (go.mod: Go, package.json / index.ts: Node.js, main.py / requirements.txt: Python).

Files listed in .thignore (or .dockerignore / .gitignore), .git, node_modules, .venv, __pycache__ and dist are left out. A Dockerfile is ignored: functions always build with the platform's runtime.

--runtime takes a runtime (python313, nodejs24, go126) or a language (python, nodejs, go: its recommended version). An existing function may move to another version of its language.

Every deploy is kept as a version (th functions versions list); --message describes it. --ingress sets who reaches the function: all (the internet, the default), internal (other services in its project) or triggers (no endpoint at all; only its Cron and Queue triggers run it). --env, --set-env-vars and --secret-env replace every variable of the function; without them the current variables stay. Settings given for an existing function (--cpu, --memory, --min-instances, ...) are applied before its code is built.

ຕົວຢ່າງ

Shell
th functions deploy hello
Shell
th functions deploy hello --runtime python314 --message "Python 3.14"
Shell
th functions deploy orders --source ./orders --memory 512Mi --max-instances 10
Shell
th functions deploy nightly-report --ingress triggers

ອາກິວເມັນຕາມຕຳແໜ່ງ

ຊື່ຄຳອະທິບາຍ
NAMEຕ້ອງໃສ່The function’s name: lowercase letters, digits and -, starting with a letter. It is also its URL slug.

ພາຣາມິເຕີ

ຊື່ປະເພດຄ່າເລີ່ມຕົ້ນຄຳອະທິບາຍ
--sourceຂໍ້ຄວາມ.Directory with the function's files
--runtimeຂໍ້ຄວາມRuntime (e.g. python313, nodejs24, go126) or language (python, nodejs, go)
--entry-pointຂໍ້ຄວາມthe runtime's, e.g. main, handler, HandleHandler name
--cpuຂໍ້ຄວາມvCPU, e.g. 0.25, 0.5, 1 (a size of the Container menu)
--memoryຂໍ້ຄວາມMemory, e.g. 256Mi, 512Mi, 1Gi
--compute-classຂໍ້ຄວາມCompute class of a new function
--envລາຍການEnvironment variable KEY=VALUE (repeatable)
--set-env-varsລາຍການEnvironment variables KEY=VALUE,KEY2=VALUE2
--secret-envລາຍການSecret environment variable KEY=VALUE (repeatable)
--min-instancesຕົວເລກMinimum instances (0 stops it when idle)
--max-instancesຕົວເລກMaximum instances
--timeoutຂໍ້ຄວາມRequest timeout, e.g. 60s or 5m
--concurrencyຕົວເລກRequests at once per instance (1-1000)
--cpu-always-allocatedແຟລັກKeep CPU between requests
--allow-unauthenticatedແຟລັກfor a new function; --no-allow-unauthenticated needs an invoker tokenAllow public calls
--ingressຂໍ້ຄວາມWho reaches the function: all, internal or triggers (no endpoint, triggers only)
--messageຂໍ້ຄວາມDescribe this version
--asyncແຟລັກReturn once the build is queued

ພາຣາມິເຕີທົ່ວໄປ

ຄຳສັ່ງນີ້ຮັບ ພາຣາມິເຕີທົ່ວໄປ ໄດ້ນຳ: --project, --region, --endpoint, --format, --quiet

ກັບຂຶ້ນເທິງ ↑

th functions list

Lists the functions of the active Project.

ຮູບແບບຄຳສັ່ງ

Shell
th functions list

ພາຣາມິເຕີທົ່ວໄປ

ຄຳສັ່ງນີ້ຮັບ ພາຣາມິເຕີທົ່ວໄປ ໄດ້ນຳ: --project, --region, --endpoint, --format, --quiet

ກັບຂຶ້ນເທິງ ↑

th functions describe

Shows a function's runtime, deploy state, settings and files.

ຮູບແບບຄຳສັ່ງ

Shell
th functions describe NAME

ອາກິວເມັນຕາມຕຳແໜ່ງ

ຊື່ຄຳອະທິບາຍ
NAMEຕ້ອງໃສ່The function’s name: lowercase letters, digits and -, starting with a letter. It is also its URL slug.

ພາຣາມິເຕີທົ່ວໄປ

ຄຳສັ່ງນີ້ຮັບ ພາຣາມິເຕີທົ່ວໄປ ໄດ້ນຳ: --project, --region, --endpoint, --format, --quiet

ກັບຂຶ້ນເທິງ ↑

th functions pull

Writes the function's saved code (what the Console editor shows), or the code of one version, into DIR (default ./NAME).

ຮູບແບບຄຳສັ່ງ

Shell
th functions pull NAME [--dir DIR] [--version N] [--force]

An existing file with other content is kept unless --force.

ອາກິວເມັນຕາມຕຳແໜ່ງ

ຊື່ຄຳອະທິບາຍ
NAMEຕ້ອງໃສ່The function’s name: lowercase letters, digits and -, starting with a letter. It is also its URL slug.

ພາຣາມິເຕີ

ຊື່ປະເພດຄ່າເລີ່ມຕົ້ນຄຳອະທິບາຍ
--dirຂໍ້ຄວາມ./NAMEDirectory to write into
--versionຂໍ້ຄວາມthe saved codeA version from th functions versions list
--forceແຟລັກOverwrite files that differ

ພາຣາມິເຕີທົ່ວໄປ

ຄຳສັ່ງນີ້ຮັບ ພາຣາມິເຕີທົ່ວໄປ ໄດ້ນຳ: --project, --region, --endpoint, --format, --quiet

ກັບຂຶ້ນເທິງ ↑

th functions call

Sends one request to the function and prints the answer.

ຮູບແບບຄຳສັ່ງ

Shell
th functions call NAME [--data BODY|@FILE] [--method POST] [--path /x] [--token TOKEN]

With --data the method defaults to POST, otherwise GET. --token is the invoker token of a function that does not allow unauthenticated calls.

ອາກິວເມັນຕາມຕຳແໜ່ງ

ຊື່ຄຳອະທິບາຍ
NAMEຕ້ອງໃສ່The function’s name: lowercase letters, digits and -, starting with a letter. It is also its URL slug.

ພາຣາມິເຕີ

ຊື່ປະເພດຄ່າເລີ່ມຕົ້ນຄຳອະທິບາຍ
--dataຂໍ້ຄວາມRequest body, or @FILE to read it from a file
--methodຂໍ້ຄວາມHTTP method
--pathຂໍ້ຄວາມ/Path to call
--tokenຂໍ້ຄວາມInvoker token

ພາຣາມິເຕີທົ່ວໄປ

ຄຳສັ່ງນີ້ຮັບ ພາຣາມິເຕີທົ່ວໄປ ໄດ້ນຳ: --project, --region, --endpoint, --format, --quiet

ກັບຂຶ້ນເທິງ ↑

th functions logs

Prints the latest log lines of a function (what the handler printed).

ຮູບແບບຄຳສັ່ງ

Shell
th functions logs NAME [--lines N]

ອາກິວເມັນຕາມຕຳແໜ່ງ

ຊື່ຄຳອະທິບາຍ
NAMEຕ້ອງໃສ່The function’s name: lowercase letters, digits and -, starting with a letter. It is also its URL slug.

ພາຣາມິເຕີ

ຊື່ປະເພດຄ່າເລີ່ມຕົ້ນຄຳອະທິບາຍ
--linesຕົວເລກ100Number of lines (default 100)

ພາຣາມິເຕີທົ່ວໄປ

ຄຳສັ່ງນີ້ຮັບ ພາຣາມິເຕີທົ່ວໄປ ໄດ້ນຳ: --project, --region, --endpoint, --format, --quiet

ກັບຂຶ້ນເທິງ ↑

th functions versions list

Lists a function's versions, newest first.

ຮູບແບບຄຳສັ່ງ

Shell
th functions versions list NAME

Every deploy is a version; the serving one is marked. The latest 30 are kept.

ອາກິວເມັນຕາມຕຳແໜ່ງ

ຊື່ຄຳອະທິບາຍ
NAMEຕ້ອງໃສ່The function’s name: lowercase letters, digits and -, starting with a letter. It is also its URL slug.

ພາຣາມິເຕີທົ່ວໄປ

ຄຳສັ່ງນີ້ຮັບ ພາຣາມິເຕີທົ່ວໄປ ໄດ້ນຳ: --project, --region, --endpoint, --format, --quiet

ກັບຂຶ້ນເທິງ ↑

th functions versions activate

Serves an earlier version again; today's settings and variables stay.

ຮູບແບບຄຳສັ່ງ

Shell
th functions versions activate NAME VERSION

When the registry no longer holds its image, its code is built again as a new version and served once the build succeeds.

ຕົວຢ່າງ

Shell
th functions versions activate hello 12
Shell
th functions versions activate hello v12

ອາກິວເມັນຕາມຕຳແໜ່ງ

ຊື່ຄຳອະທິບາຍ
NAMEຕ້ອງໃສ່The function’s name: lowercase letters, digits and -, starting with a letter. It is also its URL slug.
VERSIONຕ້ອງໃສ່

ພາຣາມິເຕີທົ່ວໄປ

ຄຳສັ່ງນີ້ຮັບ ພາຣາມິເຕີທົ່ວໄປ ໄດ້ນຳ: --project, --region, --endpoint, --format, --quiet

ກັບຂຶ້ນເທິງ ↑

th functions runtimes

Lists the runtimes a function can use and the handler each expects.

ຮູບແບບຄຳສັ່ງ

Shell
th functions runtimes

ພາຣາມິເຕີທົ່ວໄປ

ຄຳສັ່ງນີ້ຮັບ ພາຣາມິເຕີທົ່ວໄປ ໄດ້ນຳ: --project, --region, --endpoint, --format, --quiet

ກັບຂຶ້ນເທິງ ↑

th functions delete

Deletes a function with its code, triggers and revisions.

ຮູບແບບຄຳສັ່ງ

Shell
th functions delete NAME [--quiet]

--quiet skips the prompt.

ອາກິວເມັນຕາມຕຳແໜ່ງ

ຊື່ຄຳອະທິບາຍ
NAMEຕ້ອງໃສ່The function’s name: lowercase letters, digits and -, starting with a letter. It is also its URL slug.

ພາຣາມິເຕີທົ່ວໄປ

ຄຳສັ່ງນີ້ຮັບ ພາຣາມິເຕີທົ່ວໄປ ໄດ້ນຳ: --project, --region, --endpoint, --format, --quiet

ກັບຂຶ້ນເທິງ ↑