SST is a collection of npm packages that allow you to create a serverless app.
You can define your apps with a combination of Infrastructure as Code (using CDK) and Lambda functions.
Create a new project using.
Or alternatively, with a newer version of npm or Yarn.
Or if you want to use Python.
Or if you want to use Go.
By default your project is using npm as the package manager, if you'd like to use Yarn.
Note that, if you are using
npm init, you'll need to add an extra
-- before the options.
You can read more about the create-serverless-stack CLI here.
Your app starts out with the following structure.
An SST app is made up of a couple of parts.
lib/— App Infrastructure
The code that describes the infrastructure of your serverless app is placed in the
lib/directory of your project. SST uses AWS CDK, to create the infrastructure.
src/— App Code
The code that’s run when your app is invoked is placed in the
src/directory of your project. These are your Lambda functions.
test/— Unit tests
There's also a
test/directory where you can add your tests. SST uses Jest internally to run your tests.
You can change this structure around to fit your workflow. This is just a good way to get started.
lib/index.js file is the entry point for defining the infrastructure of your app. It has a default export function to add your stacks.
You'll notice that we are using
export. This is because SST automatically transpiles your ES (and TypeScript) code using esbuild.
In the sample
lib/MyStack.js you can add the resources to your stack.
Note that the stacks in SST use
sst.Stack as opposed to
cdk.Stack. This allows us to deploy the same stack to multiple environments.
In the sample app we are using a higher-level API construct to define a simple API endpoint.
The above API endpoint invokes the
handler function in
Notice that we are using
export here as well. SST also transpiles your function code.
Your SST app also includes a config file in
The stage and the region are defaults for your app and can be overridden using the
--region options. The name is used while prefixing your stack and resource names.
For TypeScript apps, SST also automatically type checks your CDK and Lambda function code using tsc. The typeCheck option allows you to turn this off.
You'll be able to access the stage, region, and name of your app in
You can also access them in your stacks,
And in TypeScript.
You can read more about the additional set of constructs that SST provides here.