Local Dev Server
Run an Amba function locally with `amba functions dev <file>` — hot reload, .env.local pass-through, and the same bundler your production deploy uses.
amba functions dev <file> spins up a local HTTP server that runs your
function exactly the way the production runtime would. Save the file
and the server rebuilds and reloads — you don't have to restart it.
Quick start
Hit the endpoint:
Edit the handler, save, and the next request runs the new code.
What it does
- Same bundler as production.
amba functions devuses the same build pipeline asamba functions deploy— externalization rules, size cap, source maps. Dev → prod parity is automatic. - Bound to loopback. The dev server only listens on
127.0.0.1so another device on your Wi-Fi can't reach your handler or read your.env.local. - Hot reload. A file save triggers a rebundle + child-process swap. In-flight requests during the swap queue at the TCP listen backlog and complete against the new bundle.
.env.localpass-through. Variables from your project's.env.localare injected into the child process so the handler can read them viaprocess.env.MY_KEY. CLI-side env wins on conflict (MY_KEY=x amba functions dev ./fn.tsoverrides the file).- Standard
Request/Response. The handler signature isasync (req: Request) => Response.fetch,URL,Headers,crypto,TextEncoderand friends are all available.
Flags
--port <n>— port to listen on (default8787).--no-watch— disable file-change hot reload. Useful when you want a stable binding (for example, when piping requests from another process that opens long-lived connections).
Handler example with .env.local secret
.env.local in the same directory:
Run:
The same code, deployed via amba functions deploy, reads its secret
from amba secrets set ECHO_TOKEN <prod-value> — see deploy.
Common pitfalls
- Port already in use — pass
--port <free-port>or kill the existing process. The dev server bails fast rather than picking a random port (so its address never moves under you while you debug). - No reload after save — confirm you didn't pass
--no-watch. Some editors save via "rename + replace" which a few filesystems don't notify on; touch the file (touch ./functions/hello.ts) to force a rebuild. process.env.Xundefined — confirmXis in your.env.localand that the variable wasn't accidentally set in your parent shell to an empty string. Parent env wins.
Next
- Deploy a function — ship the handler you just iterated on.
- CLI reference — all
amba functionssubcommands and flags.