Skip to main content
The Router component lets you create a CloudFront distribution to route requests to different origins.

Constructor

sst.config.ts
const router = new sst.aws.Router("MyRouter", {
  routes: {
    "/api/*": "https://api.example.com",
    "/uploads/*": bucket
  },
  domain: "example.com"
});

Parameters

routes

routes
Record<string, string | Bucket | object>
required
Define routes that map URL paths to destinations.
{
  routes: {
    "/api/*": "https://api.example.com",
    "/files/*": bucket
  }
}

domain

domain
string | object
Set a custom domain for your router.
{
  domain: "example.com"
}
Support for wildcard subdomains:
{
  domain: {
    name: "example.com",
    aliases: ["*.example.com"]
  }
}

Properties

url

nodes

Examples

Route to a URL

sst.config.ts
new sst.aws.Router("MyRouter", {
  routes: {
    "/api/*": "https://api.example.com"
  },
  domain: "example.com"
});

Route to an S3 bucket

sst.config.ts
const bucket = new sst.aws.Bucket("MyBucket", {
  access: "cloudfront"
});

new sst.aws.Router("MyRouter", {
  routes: {
    "/files/*": bucket
  },
  domain: "example.com"
});

Build docs developers (and LLMs) love