SST Documentation

website·Indexed 36 days ago

https://docs.sst.dev/

A framework for building modern full-stack applications on your own infrastructure.

Tokens
1.1K
Snippets
6
Records
9
Agent score
19%

What's inside SST

  1. Overview of SST Framework

    SST is a framework for building modern full-stack applications where the entire application—including infrastructure like databases, buckets, queues, and third-party providers (150+ supported)—is defined in code within a single sst.config.ts file. It automates the deployment of infrastructure to your own accounts (e.g., AWS, Cloudflare) without requiring manual console configuration.
  2. Overview of SST framework capabilities

    SST is a framework for building modern full-stack applications on your own infrastructure. It provides three primary value propositions for developers:

    1. Higher-level Components: Built-in components (such as Nextjs or Email) allow developers to add complex features without manually configuring the underlying Terraform resources.
    2. Resource Linking: SST simplifies the process of linking infrastructure resources to the application, making them accessible at runtime within the code.
    3. Unified Dev Mode: SST provides a local development environment that utilizes a watcher to deploy apps, runs functions in 'Live' mode, creates a tunnel to the VPC, and manages both frontend and backend processes simultaneously.
  3. Define application infrastructure using SST Components

    SST uses Components to define application features in code. These components automate the creation of low-level infrastructure. Common components include frontend frameworks (Next.js, Remix, Astro, SvelteKit, SolidStart), backend services (Containers, Lambda Functions, Postgres, S3 Buckets), and scheduled tasks (Cron).
    // Frontend Example
    new sst.aws.Nextjs("MyWeb", {
      domain: "my-app.com"
    });
    
    // Backend Examples
    new sst.aws.Function("MyFunction", {
      handler: "src/lambda.handler"
    });
    
    new sst.aws.Postgres("MyDatabase", { vpc });
    new sst.aws.Bucket("MyBucket");
    
    new sst.aws.Cron("MyCronJob", {
      job: "src/cron.handler",
      schedule: "rate(1 minute)"
    });
  4. Link resources to avoid hardcoding environment variables

    SST allows you to link resources together in sst.config.ts. When a resource is linked to another (e.g., a Bucket linked to a Service), the linked resource's properties become available to the application via the SST SDK, eliminating the need to hardcode identifiers.
    // sst.config.ts
    const bucket = new sst.aws.Bucket("MyBucket");
    const cluster = new sst.aws.Cluster("MyCluster", { vpc });
    
    new sst.aws.Service("MyService", {
      cluster,
      link: [bucket],
      loadBalancer: {
        ports: [{ listen: "80/http" }]
      }
    });

    // Application code (e.g., index.mjs) import { Resource } from "sst"; console.log(Resource.MyBucket.name);

  5. Organize SST projects using Drop-in or Monorepo modes

    SST supports two primary project structures:

    1. Drop-in mode: Add sst.config.ts directly to the root of an existing app (e.g., a Next.js project).
    2. Monorepo mode: Place sst.config.ts in the root and organize infrastructure logic within an infra/ directory, with application code split across a packages/ directory.
  6. Install and run the SST CLI

    For JavaScript projects, install SST as a local dependency to ensure version consistency. For non-JS projects, install the CLI globally. Use the CLI to manage the development lifecycle and deployments.
    # Installation (JS)
    npm install sst
    # or pnpm add sst / bun add sst / yarn add sst
    
    # Installation (Global/Non-JS)
    curl -fsSL https://sst.dev/install | bash
    
    # Running the CLI (JS example)
    npx sst dev
  7. Use third-party providers in sst.config.ts

    In addition to built-in AWS and Cloudflare components, SST supports over 150 Pulumi/Terraform providers, allowing you to manage other services (like Vercel) within your SST configuration.
    new vercel.Project("MyFrontend", {
      name: "my-nextjs-app"
    });
  8. Develop and deploy applications with SST CLI

    Use sst dev to start a local development environment that watches for infrastructure changes, runs functions 'Live' without redeploying, and tunnels local machines to VPC resources. Use sst deploy with the --stage flag to deploy to specific environments (e.g., production, dev, or PR-specific stages).
    # Start local development
    sst dev
    
    # Deploy to a specific stage
    sst deploy --stage production
    sst deploy --stage dev
    sst deploy --stage pr-123
  9. Configure and transform SST Components

    SST components provide sensible defaults but can be fully configured. Beyond standard options (like timeout or memory for functions), you can use the transform prop to modify the low-level resources created by a component, such as customizing an IAM Role created by a Function component.
    new sst.aws.Function("MyFunction", {
      handler: "src/lambda.handler",
      timeout: "3 minutes",
      memory: "1024 MB",
      transform: {
        role: (args) => ({
          name: `${args.name}-MyRole`
        })
      }
    });