Skip to main content

What is SST

SST is a framework that makes it easy to build and deploy full-stack serverless applications.

With SST you can create APIs, databases, frontends; connect them all together, and deploy them to AWS.


Infrastructure

SST differs from other frameworks in that it helps you with both the infrastructure for your app and your application code.

You can describe the infrastructure of your app in TypeScript or JavaScript using Constructs.


APIs

For example, you can use the Api construct to define an API in a few lines.

new Api(this, "API", {
routes: {
"GET /notes": "functions/list.main",
"POST /notes": "functions/create.main",
},
});

Behind the scenes this creates an instance of an Amazon API Gateway with a couple of routes. Each route here points to a Function. We'll look at them below.


Databases

To power your applications, SST lets you create serverless databases. Here the RDS construct configures a new Amazon RDS serverless PostgreSQL cluster.

new RDS(this, "notesDb", {
engine: "postgresql11.13",
defaultDatabaseName: "main",
migrations: "services/migrations",
});

You can also write typesafe migrations.

export async function up(db) {
await db.schema.createTable("comment").execute();
}

export async function down(db) {
await db.schema.dropTable("comment").execute();
}

In addition to SQL databases, SST also supports NoSQL serverless databases like Amazon DynamoDB.


Cron jobs

SST has constructs for most common backend use cases. For example, we can add cron jobs to our application.

new Cron(this, "cron", {
schedule: "rate(1 minute)",
job: "functions/cronjob.main",
});

You can also add Auth, Queues, Pub/Sub, Data Streams, and more.


All AWS services

Aside from the use cases that SST's constructs support, you can deploy any AWS service in SST. This is because SST is built on top of AWS CDK and you can use any CDK construct in SST.

Here we are defining an Amazon ECS cluster with an AWS CDK construct.

import * as ecs from "aws-cdk-lib/aws-ecs";

const cluster = new ecs.Cluster(this, "Cluster", {
vpc,
});

This makes it easy to extend SST to fit any use case.


Functions

At the heart of SST applications are functions — powered by AWS Lambda. These represent your application code. They are invoked by the infrastructure in your application.

From the API example above.

"GET /notes": "functions/list.main"

When a user hits the /notes route in your API, the main function in the functions/list.ts file gets executed. The API then responds with what the function returns.

export async function main() {
return {
statusCode: 200,
body: JSON.stringify([
/** list of notes **/
]),
};
}

Your functions can be in TypeScript, JavaScript, Python, Golang, Java, or C#.


Access the database

To allow your functions to securely connect to your infrastructure, SST has a concept of Resource Binding.

Following our example, you can bind the PostgreSQL database to the API.

const rds = new RDS(this, "notesDb" /* ... */);
const api = new Api(/* ... */);

api.bind([rds]);

And the functions in your API will be able to access your database.

import { RDS } from "@serverless-stack/node/rds";
import { ExecuteStatementCommand } from "@aws-sdk/client-rds-data";

export async function main() {
new ExecuteStatementCommand({
sql: "select * from notes",
secretArn: RDS.notesDb.secretArn,
resourceArn: RDS.notesDb.clusterArn,
database: RDS.notesDb.defaultDatabaseName,
});

//
}

Behind the scenes SST adds the required IAM permissions and gives you access through a typesafe client.


Frontend

For the frontend of your application, SST lets you deploy Next.js and Remix apps. Or any static website.

Here for example, we are defining a Vite static site using the StaticSite construct.

new StaticSite(this, "site", {
path: "web",
buildCommand: "npm run build",
buildOutput: "dist",
customDomain: "my-sst-app.com",
environment: {
VITE_API_URL: api.url,
},
});

Behind the scenes, this creates a static website powered by Amazon S3 and serves it through Amazon CloudFront, a CDN.


Connect to the API

SST makes it easy to connect your frontend to your API by letting you share config between constructs.

For example, you can grab the API endpoint from the API construct and pass it to our frontend as an environment variable.

const api = new Api(/* ... */);

new StaticSite(this, "site", {
// ...
environment: {
VITE_API_URL: api.url,
},
});

With SST, we don't need to hardcode our backend config in the frontend.


SST CLI

SST comes with a CLI that can deploy your applications and help you work on them locally.


Local dev

The sst start command starts a local development environment that lets you set breakpoints and test your functions locally. You don't need to mock any resources or wait for the changes to redeploy.

npx sst start

It does this by starting up a local server and proxying requests from the Lambda functions in AWS to your machine.

The sst start CLI also powers a web based dashboard called the SST Console.

SST Console homescreen

With the Console you can view and interact with your application logs in real-time. You can manually invoke functions, replay invocations, and do things like querying your database and running migrations.


Deployment

To deploy your application you use the sst deploy command.

npx sst deploy

This will convert your constructs to CloudFormation, package your functions and frontend assets, upload it to AWS, and create the infrastructure for it.

The SST CLI uses your local IAM credentials to deploy to your AWS account.


Environments

You can also deploy your app to a specific stage or environment. This lets you create separate development and production environments.

npx sst deploy --stage prod

Behind the scenes, SST uses the stage to namespace all the resources in your application.


Starters

You can create a new SST application with one of our starters and the create-sst CLI.

npx create-sst

This will set you up with a full-stack TypeScript app with all the best practices. It has a GraphQL API, PostgreSQL RDS database, and a Vite React app. This is the recommended way to start with SST.

? What kind of project do you want to create? (Use arrow keys)
❯ graphql
minimal
examples

However, if you are a more advanced user, you can pick one of our minimal templates and use the constructs to build the type of app you need.


If you are ready to get started with SST, check out our tutorial. It uses the GraphQL starter to build a simple Reddit clone.