Skip to content

Cloud Code

Cloud Code lets you run small pieces of JavaScript in the cloud, close to your AppAmbit data. Instead of standing up a backend, you write a single handler function, deploy it, and AppAmbit runs it for you — on demand, over HTTP, or in response to changes in your data.

Each function runs scoped to your app. From inside a function you can query your app database, read and publish CMS content, and send push notifications, all without shipping API keys or building a server.


What you can build

  • Custom HTTP endpoints — expose a POST /api/fn/my-endpoint URL your app can call, backed by your own logic.
  • Data automations — validate, transform, or aggregate rows in your app database.
  • CMS workflows — read entries, compute something, and publish a new entry.
  • Notifications — send a push notification when something happens.

A function is just one JavaScript module that exports a handler:

index.js
export async function handler(ctx) {
  // ctx gives you the request, your data, your secrets, and a logger
  return { ok: true, message: "Hello from Cloud Code" };
}

Whatever you return becomes the function's output (any JSON-serializable value).


Core concepts

Concept What it is
Function A named piece of code belonging to one app. It has a memory and timeout setting, a status, and one active version.
Version An immutable deploy of your source. Every time you deploy new code, you get a new version. Versions are built automatically, and only a successfully built version can be made live.
Trigger What causes your function to run — a manual run, an HTTP request, or a data event.
Invocation A single execution of your function. Each one records its status, duration, logs, and output so you can inspect what happened.

The lifecycle

Getting a function live is always the same four steps:

create ──► deploy code ──► activate a version ──► run
  1. Create a function — give it a name. It starts empty (a draft).
  2. Deploy your index.js — this creates a new version and builds it automatically. Builds are quick, but not instant.
  3. Activate the built version — this makes it the live version that runs. Your function is now active.
  4. Run it — manually, by calling its HTTP URL, or by wiring it to a data event.

Rolling back is just activating an older version

Every deploy keeps the previous versions around. If a new version misbehaves, activate a known-good older version — same operation, instant rollback.


Quick start

Here's a complete first function, from empty to running.

1. Create the function

Create a function named hello for your app. At this point it has no code yet.

2. Deploy your code

Deploy this as the function's index.js:

index.js
export async function handler(ctx) {
  const input = ctx.req ?? {};
  return {
    ok: true,
    greeting: `Hello, ${input.name ?? "world"}!`,
  };
}

Deploying returns a version number and starts an automatic build. Wait for the build to finish (its status becomes ready).

3. Activate the version

Activate the version you just built. Your function is now live.

4. Run it

Run the function with a payload:

payload
{ "name": "Ada" }

You'll get back:

output
{
  "status": "succeeded",
  "output": { "ok": true, "greeting": "Hello, Ada!" },
  "duration_ms": 12,
  "logs": []
}

That's it — you've deployed and run your first function. From here you can give it access to your data, expose it over HTTP, or run it automatically.


What's next

  • Writing Functions


    The handler signature, the ctx object, and the built-in SDK for talking to your database, CMS, and push.

    View Guide ➔

  • Triggers


    Run functions manually, expose them over HTTP, or fire them on data changes.

    View Guide ➔

  • Configuration & Limits


    Environment variables and secrets, memory and timeout settings, quotas, billing, and error codes.

    View Guide ➔

  • Examples & Tips


    Complete, copy-pasteable functions plus best practices for writing reliable Cloud Code.

    View Guide ➔