Hey all, pretty new to SST but pushing to go all i...
# help
r
Hey all, pretty new to SST but pushing to go all in on it for my org. I am trying to figure out, how can I create multiple authorizers for an API? I am following this (https://docs.serverless-stack.com/constructs/Api#adding-lambda-authorization-to-a-specific-route) but instead of using only
authorizationType
I am setting
authorizer
for two different endpoints. When I do a build I notice the authorizers are not in the JSON template at all. I only seem to be able to get one authorizer to show up and that's when I use
defaultAuthorizer
on the whole gateway. Am I missing something dumb?
f
Hey @Ross Gerbasi can u try something like this:
Copy code
const authorizer1 = new HttpLambdaAuthorizer(...);
const authorizer2 = new HttpLambdaAuthorizer(...);

new Api(this, "Api", {
  routes: {
    "GET /routeA": {
      function: "src/handlerA.main",
      authorizationType: ApiAuthorizationType.CUSTOM,
      authorizer: authorizer1,
    },
    "GET /routeB": {
      function: "src/handlerB.main",
      authorizationType: ApiAuthorizationType.CUSTOM,
      authorizer: authorizer2,
    },
  }
});
If u r using the
HttpJwtAuthorizer
, the same idea should apply.
Let me know if this works for u
r
@Frank 🤦‍♂️ I was using
handler
instead of
function
. Thanks for this.