Skip to content
GitHub Discord

Router protection with OAC

Creates a router with Origin Access Control (OAC) to secure Lambda function URLs behind CloudFront. Direct access to the Lambda URL returns 403.

sst.config.ts
const router = new sst.aws.Router("MyRouter", {
protection: "oac",
});
const api = new sst.aws.Function("MyApi", {
handler: "api.handler",
url: {
router: { instance: router, path: "/api" },
},
});
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.