Search code examples
amazon-web-servicesaws-api-gatewayserverless-framework

Custom Lambda Authorizer Event Payload type


I am trying to create a custom lambda authorizer with the lambda event payload type as "REQUEST". the serverless.yml is pretty simple

functions:
  authorizer:
    handler: src/authorizer.handler
    type: REQUEST

Whenever I deploy this yaml file it creates an authorizer with a TOKEN-based Event Payload instead of REQUEST-based.


Solution

  • The authorizer type should be set below the events section, like this:

    functions:
      hello:
        handler: handler.hello
        events:
          - http: 
              path: /hello
              method: get
              authorizer:
                name: authorizer
                type: request
                
            
      authorizer:
        handler: authorizer.handler
    

    You have instead specified the type next to "handler" on the function itself. Serverless deploys with a warning if you do this "Warning: Invalid configuration encountered at 'functions.authorizer': unrecognized property 'type'". It then defaults to "token" as type since no valid type was found.