Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/anomalyco/sst/llms.txt

Use this file to discover all available pages before exploring further.

The SST CLI is configured through the sst.config.ts file in your project root. This file defines your app, its providers, and all resources.

Basic structure

A minimal sst.config.ts looks like this:
sst.config.ts
export default $config({
  app(input) {
    return {
      name: "my-app",
      removal: input?.stage === "production" ? "retain" : "remove",
      home: "aws",
    };
  },
  async run() {
    // Your resources go here
  },
});

App configuration

The app function returns configuration for your application:

name

Type: string The name of your app. This is used to prefix all resources.
name: "my-app"

home

Type: string The default provider for your app. Can be aws, cloudflare, etc.
home: "aws"

removal

Type: "remove" | "retain" | "retain-all" The removal policy for resources:
  • remove - Resources are deleted when you run sst remove
  • retain - Resources are kept when you run sst remove
  • retain-all - All resources are kept
removal: input?.stage === "production" ? "retain" : "remove"

providers

Type: Record<string, string | ProviderConfig> Define the providers your app uses:
providers: {
  aws: "6.27.0",
  cloudflare: {
    version: "5.0.0"
  }
}

Run function

The run function is where you define your resources:
async run() {
  const bucket = new sst.aws.Bucket("MyBucket");
  const api = new sst.aws.Function("MyApi", {
    handler: "src/api.handler",
    link: [bucket],
  });
  
  return {
    api: api.url,
  };
}
The returned values are outputs that will be displayed after deployment.

Environment variables

You can access environment variables in your config:
export default $config({
  app(input) {
    return {
      name: process.env.APP_NAME || "my-app",
      // ...
    };
  },
});

Stage-specific configuration

Use the input parameter to configure based on stage:
export default $config({
  app(input) {
    return {
      name: "my-app",
      removal: input?.stage === "production" ? "retain" : "remove",
      home: "aws",
    };
  },
  async run() {
    const isProd = $app.stage === "production";
    
    new sst.aws.Function("MyFunction", {
      handler: "src/index.handler",
      memory: isProd ? "2 GB" : "1 GB",
    });
  },
});

Watch configuration

Configure which files trigger a redeploy in sst dev:
export default $config({
  app(input) {
    return {
      name: "my-app",
      watch: ["src/**/*.ts"],
    };
  },
});