Skip to content
GitHub Discord

Router and function URL

Creates a router that routes all requests to a function with a URL.

sst.config.ts
const api = new sst.aws.Function("MyApi", {
handler: "api.handler",
url: true,
});
const bucket = new sst.aws.Bucket("MyBucket", {
access: "public",
});
const router = new sst.aws.Router("MyRouter", {
routes: {
"/api/*": api.url,
"/*": $interpolate`https://${bucket.domain}`,
},
});
api.ts
export const handler = async (event: any) => {
return {
statusCode: 200,
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(event.headers),
};
};

View the full example.