Installation
SST is a collection of npm packages.
#
Requirements- Node.js >= 10.15.1
- An AWS account with the AWS CLI configured locally
#
Getting startedCreate a new project using.
Or alternatively, with a newer version of npm or Yarn.
This by default creates a JavaScript/ES project. If you instead want to use TypeScript.
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.
#
Project layoutYour app starts out with the following structure.
An SST app is made up of a couple of parts.
lib/
β App InfrastructureThe 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 CodeThe 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 testsThere'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.
#
InfrastructureThe 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 import
and 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.
#
FunctionsThe above API endpoint invokes the handler
function in src/lambda.js
.
Notice that we are using export
here as well. SST also transpiles your function code.
#
Project configYour SST app also includes a config file in sst.json
.
The stage and the region are defaults for your app and can be overridden using the --stage
and --region
options. The name is used while prefixing your stack and resource names.
SST automatically lints your CDK and Lambda function code using ESLint. The lint option allows you to turn this off.
You'll be able to access the stage, region, and name of your app in lib/index.js
.
You can also access them in your stacks, lib/MyStack.js
.
And in TypeScript.
You can read more about the additional set of constructs that SST provides here.