It seems it is not possible to set a different aut...
# help
g
It seems it is not possible to set a different authorizer per route using the Api struct in SST. It always uses the defaultAuthorizer if set, and if not set it uses no authorizer.
f
Hey @Garret Harp, you should be able to. Does this work for you
Copy code
import { HttpJwtAuthorizer } from "@aws-cdk/aws-apigatewayv2-authorizers";

new Api(this, "Api", {
  defaultAuthorizationType: ApiAuthorizationType.JWT,
  defaultAuthorizer: new HttpJwtAuthorizer({ ... }),
  routes: {
    "GET /a": "src/public.main",
    "GET /b": {
      authorizer: new HttpJwtAuthorizer({ ... }),
      function: "src/private.main",
    },
  },
});
g
Yeah just figured it out... I was using this:
Copy code
"GET /": {
  handler: "src/index.handler",
  authorizer: MyAuthorizer
}
Making it:
Copy code
"GET /": {
  function: { handler: "src/index.handler" },
  authorizer: MyAuthorizer
}
Worked. Looking back at the docs now no idea how putting handler worked as I dont think that is ever shown in the docs other than under the function object.
f
Yeah, for the route, you can either provide:
Copy code
"GET /": FunctionDefinition,
or
Copy code
"GET /": {
  function: FunctionDefinition
  authorizer: AuthorizerDefinition
}
g
Ah I see, yeah whenever using FunctionDefintion trying to specify the authorizer will not work. Might be worth pointing out in the docs 😅
f
Yeah, we need to do a better job validating the input and printing out helpful msgs.
Here’s an open issue we will be working on https://github.com/serverless-stack/serverless-stack/issues/486