# Share Auth0 custom authorizer between multiple lambda functions

**URL:** https://forum.serverless.com/t/share-auth0-custom-authorizer-between-multiple-lambda-functions/11919
**Category:** Serverless Framework
**Created:** [July 3, 2020, 3:43am UTC](https://forum.serverless.com/t/share-auth0-custom-authorizer-between-multiple-lambda-functions/11919 "2020-07-03T03:43:41Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![srshkmr](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/srshkmr/32/4378_2.png) [@srshkmr](https://forum.serverless.com/u/srshkmr)
#### Post date: [July 3, 2020, 3:43am UTC](https://forum.serverless.com/t/share-auth0-custom-authorizer-between-multiple-lambda-functions/11919/1 "2020-07-03T03:43:41Z")

</div>

I created a shared API gateway using this following example.

> **[serverless/examples](https://github.com/serverless/examples/tree/master/aws-node-shared-gateway)**
>
> Serverless Examples – A collection of boilerplates and examples of serverless architectures built with the Serverless Framework on AWS Lambda, Microsoft Azure, Google Cloud Functions, and more. - s...

Then implemented Auth0 using the following as the base.

> **[serverless/examples](https://github.com/serverless/examples/tree/master/aws-node-auth0-custom-authorizers-api)**
>
> Serverless Examples – A collection of boilerplates and examples of serverless architectures built with the Serverless Framework on AWS Lambda, Microsoft Azure, Google Cloud Functions, and more. - s...

I was trying to share this custom authorizer across other lambda scripts as well.

But I am not sure how that can be done.

SharedGateway serverless.yml

```auto
provider:
  name: aws
  runtime: nodejs12.x
  region: ap-south-1
  stage: dev
  profile: grabup-dev
  environment:
    AUTH0_CLIENT_ID: ${file(./secrets.json):AUTH0_CLIENT_ID}
    AUTH0_CLIENT_PUBLIC_KEY: ${file(./public_key)}
resources:
  Resources:
    SharedGW:
      Type: AWS::ApiGateway::RestApi
      Properties:
        Name: SharedGW
    GatewayResponse:
      Type: 'AWS::ApiGateway::GatewayResponse'
      Properties:
        ResponseParameters:
          gatewayresponse.header.Access-Control-Allow-Origin: "'*'"
          gatewayresponse.header.Access-Control-Allow-Headers: "'*'"
        ResponseType: EXPIRED_TOKEN
        RestApiId:
          Ref: SharedGW
        StatusCode: '401'
    AuthFailureGatewayResponse:
      Type: 'AWS::ApiGateway::GatewayResponse'
      Properties:
        ResponseParameters:
          gatewayresponse.header.Access-Control-Allow-Origin: "'*'"
          gatewayresponse.header.Access-Control-Allow-Headers: "'*'"
        ResponseType: UNAUTHORIZED
        RestApiId:
          Ref: SharedGW
        StatusCode: '401'
    AuthorizerPermission:
      Type: AWS::Lambda::Permission
      Properties:
        FunctionName:
          Fn::GetAtt: AuthorizerLambdaFunction.Arn
        Action: lambda:InvokeFunction
        Principal:
          Fn::Join: ["",["apigateway.", { Ref: "AWS::URLSuffix"}]]
    Authorizer:
      DependsOn:
        - SharedGW
      Type: AWS::ApiGateway::Authorizer
      Properties:
        Name: ${self:provider}-Authorizer
        RestApiId: { "Ref": "SharedGW" }
        Type: TOKEN
        IdentitySource: method.request.header.Authorization
        AuthorizerResultTtlInSeconds: 300
        AuthorizerUri:
          Fn::Join:
            - ''
            - - 'arn:aws:apigateway:'
              - Ref: "AWS::Region"
              - ':lambda:path/2015-03-31/functions/'
              - Fn::GetAtt: "AuthorizerLambdaFunction.Arn"
              - "/invocations"
  Outputs:
    apiGatewayRestApiId:
      Value:
        Ref: SharedGW
      Export:
        Name: SharedGW-restApiId
    apiGatewayRestApiRootResourceId:
      Value:
        Fn::GetAtt:
          - SharedGW
          - RootResourceId
      Export:
        Name: SharedGW-rootResourceId
    AuthorizerId:
      Value:
        Ref: Authorizer
      Export:
        Name: SharedGW-authorizerId
functions:
  authorizer:
    handler: handler.auth
  publicEndpoint:
    handler: handler.publicEndpoint
    events:
      - http:
          path: api/public
          method: get
          cors: true
  privateEndpoint:
    handler: handler.privateEndpoint
    events:
      - http:
          path: api/private
          method: get
          authorizer:
            type: CUSTOM
            authorizerId:
              Ref: Authorizer
          cors: true

```

My other products service yml file looks like the below

```auto
provider:
 name: aws
 runtime: nodejs12.x
 region: ap-south-1
 stage: dev
 profile: grabup-dev
 apiGateway:
   restApiId:
     "Fn::ImportValue": SharedGW-restApiId
   restApiRootResourceId:
     "Fn::ImportValue": SharedGW-rootResourceId
functions:
 get-products:
   handler: handler.getProducts
   events:
     - http:
         path: products/list
         method: get
         authorizer:
           type: CUSTOM
           authorizerId: !ImportValue SharedGW-authorizerId
         cors: true

```

But the error I am receiving is

```auto
An error occurred: ApiGatewayMethodApiPrivateGet - Invalid authorizer ID specified. Setting the authorization type to CUSTOM or COGNITO_USER_POOLS requires a valid authorizer. (Service: AmazonApiGateway; Status Code: 400; Error Code: BadRequestException

```

Not sure what I am missing here.
