# Request type custom authorizer issue in serverless framework

**URL:** <https://forum.serverless.com/t/request-type-custom-authorizer-issue-in-serverless-framework/17336>\
**Category:** Serverless Framework\
**Tags:** aws, lambda, api-gateway\
**Created:** [June 17, 2022, 6:01pm UTC](https://forum.serverless.com/t/request-type-custom-authorizer-issue-in-serverless-framework/17336 "2022-06-17T18:01:06Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![kiriti-iselect](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/kiriti-iselect/32/6896_2.png) [@kiriti-iselect](https://forum.serverless.com/u/kiriti-iselect)\
**Post date:** [June 17, 2022, 6:01pm UTC](https://forum.serverless.com/t/request-type-custom-authorizer-issue-in-serverless-framework/17336/1 "2022-06-17T18:01:06Z")

</div>

I always get `403` forbidden all the time. Here’s the [github code](https://github.com/kiriti999/api-gateway-request-auth.git)

Serverless URL: [https://hr4nwgnf96.execute-api.ap-southeast-2.amazonaws.com/dev/hello?auth=yes](https://hr4nwgnf96.execute-api.ap-southeast-2.amazonaws.com/dev/hello?auth=yes)

Sam URL: [https://7jjym0ms9g.execute-api.ap-southeast-2.amazonaws.com/dev/hello?auth=yes](https://7jjym0ms9g.execute-api.ap-southeast-2.amazonaws.com/dev/hello?auth=yes)

```
You can test both URL's above in postman and clearly see that 
 - sam url is working fine  
 - serverless framework url always returning 403

```

Serverless template:

```
service: sls-api-gateway-request-auth
frameworkVersion: '3'
configValidationMode: error

provider:
  name: aws
  region: ap-southeast-2
  runtime: nodejs14.x
  timeout: 30

functions:
  authFunction:
    handler: ./auth.lambda_handler

  backendFunction:
    handler: ./backend.lambda_handler
    runtime: nodejs14.x
    events:
      - http:
          method: get
          cors: true
          path: /auth
          authorizer:
            name: authFunction
            type: request

  Outputs:
    MyApiAuth:
      Description: "API Gateway endpoint URL for dev stage for api key validation in query string"
      Value: !Sub "https://{sls:instanceId}.execute-api.${AWS::Region}.amazonaws.com/dev/hello?auth=yes"

```

Here’s the SAM template which is working fine:

```
AWSTemplateFormatVersion: '2010-09-09'
Transform: 'AWS::Serverless-2016-10-31'

Resources:

  MyApi:
    Type: AWS::Serverless::Api
    Properties:
      StageName: dev
      Auth:
        DefaultAuthorizer: MyLambdaRequestAuthorizer
        Authorizers:
          MyLambdaRequestAuthorizer:
            FunctionPayloadType: REQUEST
            FunctionArn: !GetAtt authFunction.Arn
            Identity:
              QueryStrings:
                - auth
              ReauthorizeEvery: 100

  backendFunction:
    Type: 'AWS::Serverless::Function'
    Properties:
      Handler: backend.lambda_handler
      Runtime: nodejs10.x
      CodeUri: .
      Events:
        HelloAPI:
          Type: Api
          Properties:
            RestApiId: !Ref MyApi
            Path: /hello
            Method: GET

  authFunction:
    Type: 'AWS::Serverless::Function'
    Properties:
      CodeUri: .
      Handler: auth.lambda_handler
      Runtime: nodejs10.x

Outputs:
  ApiUrl:
    Description: "API endpoint URL"
    Value: !Sub 'https://${MyApi}.execute-api.${AWS::Region}.amazonaws.com/dev/hello?auth=yes'

```

I want this to be implemented using serverless framework. I am not sure why it isn’t working. I followed what ever is mentioned in official docs. Did I miss anything?

---

<div class="post-metadata">

**Author:** ![corin](https://avatars.discourse-cdn.com/v4/letter/c/6de8d8/32.png) [@corin](https://forum.serverless.com/u/corin)\
**Post date:** [June 23, 2022, 10:00pm UTC](https://forum.serverless.com/t/request-type-custom-authorizer-issue-in-serverless-framework/17336/2 "2022-06-23T22:00:28Z")

</div>

I recently added a request authorizer to my Serverless template and it was not nearly as straight forward as the docs would have you believe.

First, in Serverless the type is `CUSTOM` not request when you want a request type authorizer. Second, to convince Serverless that your authorizer really is a request authorizer and should not be a token authorizer, you need to define the authorizer in the Resources section of the template. Something like:

```auto
    AuthFunctionApiGatewayAuthorizer:
      Type: "AWS::ApiGateway::Authorizer"
      Properties:
        Name: authAuthorizer
        RestApiId:
          Ref: ApiGatewayRestApi
        AuthorizerUri:
          "Fn::Join":
            - ""
            - - "arn:"
              - Ref: "AWS::Partition"
              - ":apigateway:"
              - Ref: "AWS::Region"
              - ":lambda:path/2015-03-31/functions/"
              - Fn::GetAtt:
                  - AuthFunctionLambdaFunction
                  - Arn
              - "/invocations"
        Type: REQUEST
        AuthorizerResultTtlInSeconds: 0
        IdentitySource: ""

```

That was the only way I got it properly working.

---

<div class="post-metadata">

**Author:** ![kiriti-iselect](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/kiriti-iselect/32/6896_2.png) [@kiriti-iselect](https://forum.serverless.com/u/kiriti-iselect)\
**Post date:** [June 24, 2022, 3:25am UTC](https://forum.serverless.com/t/request-type-custom-authorizer-issue-in-serverless-framework/17336/3 "2022-06-24T03:25:44Z")

</div>

> [@corin](#):
>
> First, in Serverless the type is `CUSTOM` not request

`First, in Serverless the type is CUSTOM not request`  
You mean to say this should be like:

```auto
authorizer:
    name: authFunction
    type: custom

```

But the docs here says it should be `type: request`. See the attached screenshot

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/serverless/original/2X/1/16df769a98237f69674be3b33454e5e8c09b107b.png)

Can you please provide any link to docs you found?

---

<div class="post-metadata">

**Author:** ![corin](https://avatars.discourse-cdn.com/v4/letter/c/6de8d8/32.png) [@corin](https://forum.serverless.com/u/corin)\
**Post date:** [June 27, 2022, 2:35pm UTC](https://forum.serverless.com/t/request-type-custom-authorizer-issue-in-serverless-framework/17336/4 "2022-06-27T14:35:56Z")

</div>

I can’t provide any relevant documentation for it. This comes from various examples and lots of trial and error. However, it just occurred to me we may not be talking about the same version. I know I’m a little behind on Serverless versions, which version are you using?
