What is sst?
The SST (Serverless Stack Toolkit) npm package is a framework for building serverless applications. It provides a set of tools and abstractions to simplify the development, deployment, and management of serverless applications on AWS. SST supports various AWS services and allows developers to define their infrastructure as code using AWS CDK (Cloud Development Kit).
What are sst's main functionalities?
Define Infrastructure
This feature allows you to define your cloud infrastructure using SST. In this example, an S3 bucket is created within a stack.
const sst = require('@serverless-stack/resources');
class MyStack extends sst.Stack {
constructor(scope, id, props) {
super(scope, id, props);
// Define an S3 bucket
const bucket = new sst.Bucket(this, 'MyBucket');
}
}
module.exports = function main(app) {
new MyStack(app, 'my-stack');
};
Deploy Lambda Functions
This feature allows you to deploy AWS Lambda functions easily. In this example, a Lambda function is defined with a handler located at 'src/lambda.handler'.
const sst = require('@serverless-stack/resources');
class MyStack extends sst.Stack {
constructor(scope, id, props) {
super(scope, id, props);
// Define a Lambda function
const lambda = new sst.Function(this, 'MyFunction', {
handler: 'src/lambda.handler',
});
}
}
module.exports = function main(app) {
new MyStack(app, 'my-stack');
};
API Gateway Integration
This feature allows you to integrate API Gateway with your Lambda functions. In this example, an API Gateway is created with a route that triggers the Lambda function defined at 'src/lambda.handler'.
const sst = require('@serverless-stack/resources');
class MyStack extends sst.Stack {
constructor(scope, id, props) {
super(scope, id, props);
// Define an API Gateway
const api = new sst.Api(this, 'Api', {
routes: {
'GET /': 'src/lambda.handler',
},
});
}
}
module.exports = function main(app) {
new MyStack(app, 'my-stack');
};
Other packages similar to sst
serverless
The Serverless Framework is a popular open-source framework for building and deploying serverless applications. It supports multiple cloud providers, including AWS, Azure, and Google Cloud. Compared to SST, Serverless Framework offers a more extensive plugin ecosystem and broader cloud provider support, but SST provides tighter integration with AWS CDK.
aws-cdk
The AWS Cloud Development Kit (CDK) is a framework for defining cloud infrastructure using familiar programming languages. It allows developers to define their infrastructure as code and provides high-level constructs for AWS services. While SST uses AWS CDK under the hood, it adds additional abstractions and tools specifically for serverless applications, making it easier to work with serverless architectures.
pulumi
Pulumi is an infrastructure as code tool that allows developers to define cloud resources using general-purpose programming languages. It supports multiple cloud providers and offers a flexible and modern approach to infrastructure management. Compared to SST, Pulumi provides broader cloud provider support and language flexibility, but SST offers a more focused experience for AWS serverless applications.
SST 2.0 Preview
This is a preview of the upcoming SST 2.0. It is incomplete so if you run into any issues please report to us in the #cli channel in discord ASAP so we can get it fixed. We're in the final phases now and are trying to prioritize fixing blocking issues.
!!! DO NOT USE FOR PRODUCTION !!!
Migration Guide
- SST is now a monopackage. Remove all packages referencing
@serverless-stack/resources
and @serverless-stack/cli
. - Install the
sst@snapshot
package - hell yeah we got this name - You can now specify
sst.json
as sst.config.mjs
file. Here's an example:
const PROFILE = {
staging: "bumi-staging",
production: "bumi-production",
default: "bumi-dev",
}
export default function (input) {
return {
name: "bumi",
region: "us-east-1",
main: "stacks/index.ts",
profile: PROFILE[input.stage] || PROFILE.default,
}
}
- A temporary thing we need to do right now is to update your root
tsconfig.json
with this setting
"compilerOptions": {
"moduleResolution": "nodenext"
}
A side effect of this is all imports in your stack code will need to end with .js
- this is the future of nodejs so it is worth doing now.
- In your stacks code replace all imports from
@serverless-stack/resources
to sst/constructs
- We've made changes to the
FunctionProps
API so you should be seeing type errors around the bundle
property. Most of the options there have been moved to a nodejs
property instead - We've removed the need for
srcPath
in function definitions but all your handler paths need to be specified relative to the root of the project.
Before
new Function(stack, "fn", {
srcPath: "services",
handler: "path/to/func.handler"
})
After
new Function(stack, "fn", {
handler: "services/path/to/func.handler"
})
New Projects
There is also a preview of create-sst
You can use it by running npx create-sst@snapshot
Not yet supported
- Any runtime other than nodejs
- SST Console
Tell us about anything else that's missing outside of this!