Examples
A collection of example apps for reference.
Below are a collection of example SST apps. These are available in the examples/
directory of the repo.
The descriptions for these examples are generated using the comments in the sst.config.ts
of the app.
Contributing
To contribute an example or to edit one, submit a PR to the repo.
Make sure to document the sst.config.ts
in your example.
API Gateway auth
Enable IAM and JWT authorizers for API Gateway routes.
View the full example.
Bucket notifications
Create an S3 bucket and subscribe to its events with a function.
View the full example.
DynamoDB streams
Create a DynamoDB table, enable streams, and subscribe to it with a function.
View the full example.
IAM permissions boundaries
Use permissions boundaries to set the maximum permissions for all IAM roles that’ll be created in your app.
In this example, the Function has the s3:ListAllMyBuckets
and sqs:ListQueues
permissions. However, we create a permissions boundary that only allows s3:ListAllMyBuckets
.
And we apply it to all Roles in the app using the global
$transform
.
As a result, the Function is only allowed to list S3 buckets. If you open the deployed URL, you’ll see that the SQS list call fails.
Learn more about AWS IAM permissions boundaries.
View the full example.
Current AWS account
You can use the aws.getXXXXOutput()
provider functions to get info about the current
AWS account.
Learn more about provider functions.
View the full example.
AWS monorepo
A full-stack TypeScript monorepo template that deploys a frontend, a database, and an API to AWS.
While, drop-in mode is great for simple projects, we recommend using this template for projects that are going to have multiple packages.
Project structure
The app is split into the separate packages/
and an infra/
directory.
The packages/
directory includes the following:
-
core/
This directory includes shared code that can be used by other packages. These are defined as modules. For example, we have an
Example
module.We exports this using the following in the
package.json
:This will allow us to import the
Example
module by doing: -
functions/
This directory includes our Lambda funcitons. It imports from the
core/
package by using it as a local dependency. -
frontend/
This directory includes a simple Vite app. It references environment variables from our app and is started locally using.
-
scripts/
This directory includes scripts that you can run on your SST app using the
sst shell
CLI andtsx
. For example, to the run the examplescripts/src/example.ts
, run the following frompackages/scripts/
.
Infrastructure
The infra/
directory allows you to logically split the infrastructure of your app into
separate files. This can be helpful as your app grows.
In the template, we have an api.ts
, database.ts
, and frontend.ts
. These export
resources that can be used in the other infrastructure files.
They are also re-exported in the infra/index.ts
file.
And to use them in your sst.config.ts
we do an dynamic import. This ensures that the
infrastructure is only created in the run
function.
View the full example.
Subscribe to queues
Create an SQS queue, subscribe to it, and publish to it from a function.
View the full example.
Router and function URL
Creates a router that routes all requests to a function with a URL.
View the full example.
Simple static site
Deploy a simple HTML file as a static site with S3 and CloudFront.
View the full example.
Swift on Lambda
Deploys a simple Swift application to Lambda using the al2023
runtime.
Check out the README in the repo for more details.
View the full example.
Subscribe to topics
Create an SNS topic, publish to it from a function, and subscribe to it with a function and a queue.
View the full example.
Vector search
Store and search for vector data using the Vector component. Includes a seeder API that uses an LLM to generate embeddings for some movies and optionally their posters.
Once seeded, you can call the search API to query the vector database.
View the full example.
React SPA with Vite
Deploy a React single-page app (SPA) with Vite to S3 and CloudFront.
View the full example.
Cloudflare KV
This example creates a Cloudflare KV namespace and links it to a worker. Now you can use the SDK to interact with the KV namespace in your worker.
View the full example.
Default function props
Set default props for all the functions in your app using the global $transform
.
View the full example.
Vercel domains
Creates a router that uses domains purchased through and hosted in your Vercel account.
Ensure the VERCEL_API_TOKEN
and VERCEL_TEAM_ID
environment variables are set.
View the full example.