[Solved] Multiple custom authorizers for one gateway?

Hi!

I was hoping to deploy an API Gateway with two endpoints, each using a different Custom Authorizer lambda.

I have the authorizer lambdas deployed, and I referred to them in the serverless yaml by their ARNs.

However, when deployed, I noticed that the gateway created ended up having only one authorizer function, named authorizer, not the two authorizers I’d expected.

My yaml looks something like this:

functions:
  helloWithAuth1:
    handler: handler.hello
    events:
      - http: 
          path: hello-auth-1
          method: get
          authorizer:
            arn: arn-foo-bar-111
            resultTtlInSeconds: 0
            type: request
  helloWithAuth2:
    handler: handler.hello
    events:
      - http:
          path: hello-auth-2
          method: get
          authorizer:
            arn: arn-foo-bar-222
            resultTtlInSeconds: 0
            type: request

My question, then, is this:

Is there a way for Serverless to deploy a gateway with multiple authorizers?

Thank you,
Daniel

ps. I noticed this question is similar to one asked back in Nov — Custom Authorizer configuration for multiple endpoints in the same API — but there the posters wanted one authorizer, but two behaviors (different caching per endpoint.) Here, I want to reference two separate authorizers.

Nevermind! It seems this was fixed in Serverless 1.26. For anyone seeing in this in the future, note, it looks to me like you’ll want to specify an authorizer name, so, your yaml would look something like this:

functions:
  helloWithAuth1:
    handler: handler.hello
    events:
      - http: 
          path: hello-auth-1
          method: get
          authorizer:
            name: auth-1
            arn: arn-foo-bar-111
            resultTtlInSeconds: 0
            type: request
  helloWithAuth2:
    handler: handler.hello
    events:
      - http:
          path: hello-auth-2
          method: get
          authorizer:
            name: auth-2
            arn: arn-foo-bar-222
            resultTtlInSeconds: 0
            type: request
1 Like