Skip to main content

Constructs

Import from sst/constructs to add a construct to your app.

Use Constructs to add any feature to your app. Like a frontend, database, API, cron job, etc.


About

A Construct is a TypeScript or JavaScript class, and each class corresponds to a feature of your app.

SST's constructs are built on top of AWS CDK. They are designed to address specific use cases and have sensible defaults that make it easier to use AWS.

However, you can configure these defaults. You can even use CDK constructs in your SST app. To learn more read about our design principles.


Installation

The constructs are available through the sst npm package.

npm install sst@two --save-exact

If you are using our starters, the sst package should already be installed.


Usage

You can then import the constructs through sst/constructs.

import { Api } from "sst/constructs";

And then add that feature by creating a new instance in your stacks.

new Api(stack, "Api", {
routes: {
"GET /notes": "src/list.main",
},
});

Types of constructs

Check out the sidebar on the left for the different kinds of constructs that SST has. Including:

  • Core: Used by every SST app.
  • Frontend: Deploys a frontend to AWS.
  • Database: Add a serverless database to your app.
  • API: Add a dedicated API to your app.
  • Async: This includes async features like cron jobs, long running jobs, queues, etc.
  • S3 buckets, and more.