API GW Custom Authorizer

Hi All

I have a custom authoriser defined via Resources section of my stacks serverless.yml.

Looking at the docs for custom authorizers it seems to want the arn of the Lambda function. However I want to specify the custom authorizer created by CF.

Possible?

I created the authorizer via CF as it always seems to fail when trying to create within the function itself. Retrying that now and will update with results

Thanks
Mark

The usual way to create a custom authorizer is to just create a function you want to act as your authorizer (which it sounds like you already have) but add no event to it. Then when you have a fun ction you want to make use of the custom authorizer just pass the name of that authorizer function you created previously and API Gateway will automatically use your custom authorizer. There’s an example config at https://serverless.com/framework/docs/providers/aws/events/apigateway/#http-endpoints-with-custom-authorizers

functions:
  create:
    handler: posts.create
    events:
      - http:
          path: posts/create
          method: post
          authorizer: authorizerFunc
  authorizerFunc:
    handler: handler.authorizerFunc

Hope that helps

Thanks

Yes I tried that initially but it kept barfing about some of the params I was setting as I needed type:request and identitySources etc etc.

So then I took the approach of creating an authorizer via CF and was hoping to simply reference it but the docs dont really tell you how.

I since retried defining the authorizer within the function much like your example and it works fine.

FYI - This morning I spotted this - https://github.com/serverless/serverless/issues/6125 which proves you could actually reference an authorizer previously created in CF

Cheers for helping out!!