Skip to main content

Constructs

Constructs are the basic building blocks of SST apps.


They allow you to define the infrastructure of your app. Each construct bring together multiple AWS resources to make up a functional unit.

Behind the scenes

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. Read more about the design principles we use to build our constructs.

The @serverless-stack/resources package provides a set of additional CDK constructs necessary to build an SST app.


Installation

This package is usually installed together with @serverless-stack/cli.

# With npm
npm install @serverless-stack/cli @serverless-stack/resources --save-exact
# Or with Yarn
yarn add @serverless-stack/cli @serverless-stack/resources --exact

Note that, the version of these packages should be kept in sync.


Importing constructs

You can either import specific constructs in your app.

import { Api } from "@serverless-stack/resources";

Or import them all.

import * as sst from "@serverless-stack/resources";

Type of constructs

SST comes with a two types of constructs.

Low-level

These either extend or replace the native CDK constructs.

Higher-level

These are higher level abstractions that wrap around multiple constructs to serve specific use cases.