Using resources
A resource is a piece of cloud infrastructure your code uses, such as a bucket, a key-value store, or a queue. Every resource works the same way: you declare it in alien.ts, connect it to the code that uses it, and call it from that code.
const documents = new alien.Storage("documents").versioning(true).build()
const index = new alien.Kv("index").build()
const processor = new alien.Worker("processor")
.code({ type: "source", src: "./processor", toolchain: { type: "typescript" } })
.link(documents)
.link(index)
.permissions("processor")
.build()import { kv, storage } from "@alienplatform/sdk"
const documents = storage("documents")
const index = kv("index")
async function main() {
const file = await documents.get("contracts/2026/msa.pdf")
await index.setJson("doc:contracts/2026/msa.pdf", { bytes: file.data.length })
}
void main()Alien creates the native service on each platform. On AWS, documents is an S3 bucket and index is a DynamoDB table. On Google Cloud, the same code reads Cloud Storage and writes Firestore.
Declare
Every builder follows one pattern: new alien.X(id), chained setters, then .build(). Add the result to the stack with .add(resource, "frozen") or .add(resource, "live"), which decides who creates and changes it. See Frozen or live.
Link
A link connects a resource to a workload, the code that uses it. .link() does two things:
- It injects the resource's connection details into the workload's environment.
- It grants access through the workload's permission profile, the named set of cloud permissions the workload runs with. Name the resource in the profile to choose the exact access.
Code can only reach resources it is linked to. The cloud enforces this through the workload's identity.
Call from code
A binding is how your code calls a linked resource: Alien injects the resource's connection details into the workload, and an Alien SDK client reads them. Each client factory takes the resource id from alien.ts, as in storage("documents") above.
Use the SDK for your language. It reads the binding, authenticates with the workload's cloud identity, and returns a ready client, so your code doesn't parse environment variables or call the cloud's secret store.
| Language | Package | Install | Reference |
|---|---|---|---|
| TypeScript | @alienplatform/sdk | npm install @alienplatform/sdk | TypeScript SDK |
| Python | alienplatform | pip install alienplatform | Python SDK |
| Rust | alien-sdk | cargo add alien-sdk | Rust SDK |
Creating a binding does no network I/O. The first call resolves the resource and authenticates with the workload's cloud identity: an IAM role on AWS, a service account on Google Cloud, a managed identity on Azure. Your code holds no keys or connection strings.
Containers and Daemons use the same bindings. A TypeScript service that isn't built from source imports them from @alienplatform/bindings.
Database, bucket, and service URL
A workload that uses a linked Postgres database, a Storage bucket, and another Container:
import { container, postgres, storage } from "@alienplatform/sdk"
import pg from "pg"
const conn = await postgres("db").connection()
const pool = new pg.Pool({
host: conn.host,
port: conn.port,
database: conn.database,
user: conn.username,
password: conn.password,
ssl: conn.ssl,
})
await storage("documents").put("reports/today.json", Buffer.from("{}"))
const ocrUrl = await container("ocr").getInternalUrl()postgres(...).connection() reads the database password from the cloud's secret store with the workload's identity, and the SQLAlchemy helper adds the provider's CA certificates. Don't build the connection URL or call Secrets Manager yourself. See Postgres.
What a link injects
Linking a resource injects ALIEN_<ID>_BINDING into the workload: a JSON description of the provisioned service. The id is uppercased and hyphens become underscores. The SDK reads it for you. See Environment variables.
Cloud SDKs
Read the binding yourself only for a feature the Alien SDK doesn't wrap, such as DynamoDB streams or Pub/Sub ordering keys, or to give the native bucket name to a client you already keep. The binding carries the native identifiers, so you can call the cloud's own SDK in any language. Both approaches work in the same app.
import { S3Client, GetObjectCommand } from "@aws-sdk/client-s3"
const binding = JSON.parse(process.env.ALIEN_DOCUMENTS_BINDING!)
// { service: "s3", bucketName: "...", region: "us-east-1" }
const s3 = new S3Client({ region: binding.region })
await s3.send(new GetObjectCommand({ Bucket: binding.bucketName, Key: "report.json" }))The Alien SDKs don't return a Storage's native bucket name. Read bucketName from the binding, as above. The field depends on service: s3 and gcs carry bucketName, blob carries accountName and containerName, and local-storage carries storagePath. Some resources, such as Email, have no Alien client and are used this way.
Frozen or live
Each resource is added to the stack as "frozen" or "live". The difference is who creates and changes it:
- Frozen: the customer's admin creates it once, during initial setup, with their own credentials. Alien can't change it afterward.
- Live: Alien creates and updates it on every release, through the deployment's management identity, a scoped identity in the customer's account.
See Frozen and live resources. Stack.add() always takes the lifecycle explicitly. Each resource accepts:
| Resource | Lifecycle |
|---|---|
| Worker, Container, Daemon | Live |
| ComputeCluster | Frozen |
| Sandbox | Frozen (Live on AWS) |
| Storage, Kv, Queue, Vault, Postgres, Redis, AI | Frozen or live |
| Key, Email, Network | Frozen |
| ArtifactRegistry, Build, ServiceAccount | Frozen |
Resources Alien adds for you, such as the Network and a ServiceAccount per permission profile, are frozen. ArtifactRegistry and Key are frozen, but the management identity can still manage what's inside them, such as repositories and access grants.
Optional resources
.enabled(input) creates a resource only when a boolean input the admin answers at initial setup is true, for example an AI resource that only some customers turn on. See Inputs and secrets.
A frozen gated resource keeps the answer given at creation. A live gated resource follows later edits to the input, and turning it off deletes the resource and its data.
Common to every resource
| Member | Notes |
|---|---|
new alien.X(id) | Ids match [A-Za-z0-9-_], at most 64 characters. Container and Sandbox ids must be DNS-compatible (lowercase letters, digits, hyphens). |
.build() | Validates the config against its schema and returns a Resource. Throws on invalid input. |
.enabled(input) | Creates the resource only when a boolean stack input is true. Not on ArtifactRegistry, Build, ServiceAccount, or ComputeCluster. |
static any() | Returns the resource type, for permission targets that cover every resource of that type. |
resource.ref() | Returns { type, id }, used by triggers and links. |
Common patterns
Hand out an upload URL. Your code creates a signed URL, and the customer's browser uploads straight into their bucket. The file never passes through your cloud:
const upload = await documents.signedUrl({ method: "PUT", path: "inbox/new.pdf", expiresIn: 900 })React to new data. A Worker trigger runs a handler for each event:
{ type: "storage", storage, events: ["created"] }withonStorageEvent{ type: "queue", queue }withonQueueMessage{ type: "schedule", cron }withonCronEvent
Delivery can repeat, so make handlers safe to run twice.
Call another service in the stack. Link a Container to the Worker, then read its private URL: container("ocr").getInternalUrl() in TypeScript, await container("ocr").internal_url() in Python. See Database, bucket, and service URL.
Local development
alien dev runs your stack on your machine with no cloud credentials. Most resources get a local equivalent behind the same SDK calls, so code that runs locally runs unchanged in a customer's cloud.
AI uses your own provider key locally, and Email is AWS only. See Local development.
Next
- Choose compute: pick a Worker, Container, or Daemon for each workload
- Frozen and live resources: who creates and changes each resource
- Permissions: choose exactly what each workload can do
- Remote bindings: use a resource from your own backend