DEV Community

Alex Spinov
Alex Spinov

Posted on

Pulumi Has a Free Automation API That Replaces Your Shell Scripts

Pulumi's Automation API lets you embed infrastructure-as-code directly inside your applications. Define, deploy, and destroy cloud resources programmatically from TypeScript, Python, Go, or C#.

What Is the Automation API?

Instead of running pulumi up from the terminal, you call it from code:

import { LocalWorkspace } from "@pulumi/pulumi/automation";

const stack = await LocalWorkspace.createOrSelectStack({
  stackName: "dev",
  projectName: "my-infra",
  program: async () => {
    const aws = require("@pulumi/aws");
    const bucket = new aws.s3.Bucket("my-bucket", {
      website: { indexDocument: "index.html" }
    });
    return { bucketUrl: bucket.websiteEndpoint };
  }
});

const result = await stack.up({ onOutput: console.log });
console.log(`Bucket URL: ${result.outputs.bucketUrl.value}`);
Enter fullscreen mode Exit fullscreen mode

Key Use Cases

1. Self-Service Infrastructure Portals

app.post("/api/create-environment", async (req, res) => {
  const { teamName, size } = req.body;
  const stack = await LocalWorkspace.createStack({
    stackName: `env-${teamName}`,
    projectName: "environments",
    program: async () => { /* Deploy EKS, RDS, etc. */ }
  });
  await stack.setConfig("size", { value: size });
  const result = await stack.up();
  res.json({ url: result.outputs.url.value });
});
Enter fullscreen mode Exit fullscreen mode

2. Testing Infrastructure

describe("S3 bucket", () => {
  let stack;
  beforeAll(async () => {
    stack = await LocalWorkspace.createStack({
      stackName: `test-${Date.now()}`,
      projectName: "test-infra",
      program: myInfraProgram
    });
    await stack.up();
  });
  afterAll(async () => {
    await stack.destroy();
  });
  it("should be accessible", async () => {
    const outputs = await stack.outputs();
    const res = await fetch(outputs.url.value);
    expect(res.status).toBe(200);
  });
});
Enter fullscreen mode Exit fullscreen mode

3. Stack Management

const stacks = await workspace.listStacks();
const outputs = await stack.outputs();
const preview = await stack.preview();
await stack.refresh();
const state = await stack.exportStack();
Enter fullscreen mode Exit fullscreen mode

Why This Matters

The Automation API turns infrastructure into a library, not a CLI tool. This enables:

  • Platform engineering self-service portals
  • SaaS per-tenant infrastructure provisioning
  • Test suites with real cloud resources
  • Custom deployment pipelines beyond CI/CD tools

Need custom infrastructure automation or cloud deployment tools? I build developer tools and data pipelines. Check out my web scraping actors on Apify or reach out at spinov001@gmail.com for custom solutions.

Top comments (0)