Docs

Worker

A Worker is stateless code that runs on the cloud's serverless runtime and costs nothing while idle. It fits HTTP APIs, webhooks, queue consumers, storage event handlers, and scheduled jobs.

alien.ts
import * as alien from "@alienplatform/core"

const api = new alien.Worker("api")
  .code({ type: "source", src: "./api", toolchain: { type: "typescript" } })
  .publicEndpoint("api")
  .permissions("execution")
  .build()

export default new alien.Stack("acme")
  .add(api, "live")
  .permissions({ profiles: { execution: {} } })
  .build()

.permissions("execution") names the Worker's permission profile, the set of cloud permissions it runs with. execution grants nothing here, because the Worker uses no other resource.

PlatformWhat Alien createsScales to zero
AWSLambda function from a container image, ARM64 (Graviton)Yes
Google CloudCloud Run service (gen2 execution environment)Yes
AzureContainer App in the stack's Container Apps environmentPrivate Workers only. A Worker with a public endpoint keeps one replica running.
KubernetesDeployment and Service, one replicaNo
MachinesNot supported. Use a Daemon or a stateless Container.
LocalNative process extracted from the built imageNo

A Worker is always "live": Alien creates and updates it on every release, and the build refuses any other lifecycle. See Frozen and live. Triggers per platform are in Events and triggers.

When to use another type

  • Container: long-running processes, persistent connections such as WebSockets, state on disk, or more than one hour per request.
  • Daemon: one process per machine.

Use it from code

Register handlers from @alienplatform/sdk in the entry module. The default export is an HTTP app that serves the public endpoint.

api/src/index.ts
import { Hono } from "hono"
import { command, onQueueMessage, waitUntil } from "@alienplatform/sdk"
import { z } from "zod"

const app = new Hono()
app.get("/health", c => c.json({ ok: true }))

const ResizeInput = z.object({ id: z.string() })

command("resize", ResizeInput, async ({ id }, ctx) => {
  return { id, attempt: ctx.attempt }
})

onQueueMessage<{ imageId: string }>("tasks", async message => {
  console.log(message.payload.imageId, message.attemptCount)
})

export default app

Every handler and type is listed in the API reference.

Common patterns

Public API. Add .publicEndpoint("api") and export an HTTP app. Add .readinessProbe({ path: "/health" }) so each deploy waits until the new version answers. See Networking.

Queue consumer. Add a queue trigger and register onQueueMessage. Make the handler idempotent, because delivery is at least once. For throughput, opt into batches. See Events and triggers.

Scheduled job. Add .trigger({ type: "schedule", cron: "0 3 * * *" }) and register onCronEvent. Schedules run in UTC.

Operations you trigger in each environment. Enable .commandsEnabled(true) and register command() handlers, for example to run a migration or collect diagnostics in one customer's environment. Your own backend calls them through Alien, so the Worker needs no public endpoint and the environment needs no inbound access. See Commands.

Call another Worker. Call its public endpoint, or send it a command:

import { CommandsClient } from "@alienplatform/commands"

const commands = new CommandsClient({ managerUrl, deploymentId, token })
const result = await commands.target("image-processor").invoke("resize", payload)

From Rust or Python, link the target Worker and call it through its binding. See Worker binding.

Background work after the response. Use waitUntil for logging, analytics, and cache updates.

Options

MethodTypeDefaultNotes
.code(code)WorkerCoderequiredPrebuilt image or source build. See Toolchains.
.permissions(profile)stringrequiredPermission profile name.
.memoryMb(mb)number512128 to 32,768. AWS allows up to 10,240. Google Cloud requires at least 512. Azure uses fixed pairs from 512 to 4,096 and rounds up. See Memory.
.timeoutSeconds(sec)number1801 to 3,600. AWS Lambda stops at 900.
.concurrencyLimit(n)number | undefinedplatform defaultReserved concurrency on Lambda, max instances on Cloud Run, max replicas on Container Apps.
.publicEndpoint(name, opts?)string, { hostLabel?, wildcardSubdomains? }none (private)Named HTTPS endpoint. Repeatable. hostLabel: "@" serves the domain apex. wildcardSubdomains defaults to false. Can't change after create.
.readinessProbe(probe){ method?, path? }noneChecked after each deploy. Needs a public endpoint. Method defaults to GET, path to /.
.commandsEnabled(on)booleanfalseLets the Worker receive commands.
.trigger(trigger)WorkerTriggernoneRepeatable. See Events and triggers.
.environment(vars)Record<string, string>{}Replaces the whole map. Names reserved by Alien are refused.
.link(resource)ResourcenoneRepeatable. Injects the resource's binding and grants the profile's permissions on it.
.enabled(input)boolean stack inputalwaysSee Using resources.

The Worker ID is part of cloud resource names. Use lowercase letters, digits, and single hyphens. It can be at most 23 characters on Azure and 55 on AWS.

Environment variables

.environment() sets fixed values. Per-deployment values and secrets are set when the deployment is created.

Alien injects ALIEN_* variables, including one ALIEN_<NAME>_BINDING per linked resource. See Environment variables for the injected names, the CLI flags, and the reserved names.

Permissions

SetGrants
worker/executeRuntime needs of the Worker itself, such as image pull and logs.
worker/invokeInvoking the Worker from another workload.
worker/dispatch-commandDispatching commands to the Worker. Added when commands are enabled.
worker/provision, worker/management, worker/heartbeatUsed by initial setup and the management identity.

Next

On this page