Skip to content
GitHub Discord

API Gateway auth

Enable IAM and JWT authorizers for API Gateway routes.

sst.config.ts
const api = new sst.aws.ApiGatewayV2("MyApi", {
domain: {
name: "api.ion.sst.sh",
path: "v1",
},
});
api.route("GET /", {
handler: "route.handler",
});
api.route("GET /foo", "route.handler", { auth: { iam: true } });
api.route("GET /bar", "route.handler", {
auth: {
jwt: {
issuer:
"https://cognito-idp.us-east-1.amazonaws.com/us-east-1_Rq4d8zILG",
audiences: ["user@example.com"],
},
},
});
api.route("$default", "route.handler");
route.ts
export const handler = async (event) => {
console.log(event);
return {
statusCode: 200,
body: JSON.stringify({ route: event.routeKey, status: "ok" }, null, 2),
};
};

View the full example.