Amba

Quickstart

Deploy your first Amba function in under a minute. Amba runtime modules, no wrappers.

A function in 15 lines of code.

1. Write the function

functions/hello.ts:

export default {
  async fetch(req: Request, env: Env, _ctx: ExecutionContext): Promise<Response> {
    const userId = req.headers.get('X-Amba-User-Id') || 'anonymous';
    return Response.json({ hello: userId, project: env.AMBA_PROJECT_ID });
  },
};
 
interface Env {
  AMBA_API_URL: string;
  AMBA_PROJECT_ID: string;
  AMBA_INTERNAL_TOKEN: string;
  EDGE_HEADER_SIGNING_SECRET: string;
  AMBA_AI_GATEWAY_URL: string;
  STORAGE?: unknown; // object storage handle; type depends on the storage client you choose
}

The default export is the Amba runtime module shape ({ async fetch(req, env, ctx) }). The runtime injects env bindings at deploy time — see Runtime for the full list. There is no @layers/amba-* import; the bundle stays self-contained.

2. Deploy

amba functions deploy ./functions/hello.ts

Output (silent-until-done):

✓ deployed hello
  url:     https://hello.<project>.fn.amba.host
  version: 1
  size:    0.4KB compressed (0.7KB raw)

amba functions deploy bundles with esbuild (--bundle --format=esm --platform=browser --target=es2022), checks the size against the 8 MB cap, POSTs to the admin API, and waits for the runtime to acknowledge.

3. Call it

curl https://hello.<project>.fn.amba.host
# {"hello":"anonymous","project":"b61415c0-…"}

Authenticated calls go through the edge router which signs X-Amba-User-Id for you when the request carries a valid X-Api-Key + session token. Anything calling *.fn.amba.host directly without those headers gets anonymous.

4. Call back into Amba

To read a collection, send a push, grant currency, etc., fetch the project-scoped admin API using env.AMBA_INTERNAL_TOKEN. This token is scoped to this project only — it authenticates /v1/admin/projects/${env.AMBA_PROJECT_ID}/* and nothing else. Global admin operations (creating projects, listing developer-owned projects) require a developer PAT instead. See Token reference for the full breakdown.

const res = await fetch(
  `${env.AMBA_API_URL}/v1/admin/projects/${env.AMBA_PROJECT_ID}/collections/configs/rows?key=launch_config`,
  { headers: { Authorization: `Bearer ${env.AMBA_INTERNAL_TOKEN}` } },
);
const { data } = await res.json();

Full endpoint catalog: /api-reference/admin.

Next

  • Runtime contract — every binding, every header, every error code → fix.
  • Local dev — iterate on a function without deploying.
  • Deploy — the deploy lifecycle, rollback, scheduled invocations.

On this page