title: Unable to use custom authorizer in API Gateway
body: <p>I have a couple of days trying to secure my API Gateway using custom authorizers with the auth0 service. I have my lambda which validates my bearer token, the Lambda does work if I invoke it inside the AWS console and when I create a custom authorizer I can successfully tested with a Bearer token.</p>
  
  <p>When I try to attach the authorizer to my API Gateway methods and test the request with postman and the token provided by auth0 it always returns a 401 status code. I read my logs in CloudWatch and the authorization Lambda it's never triggered whenever I make the HTTP request. I am following this tutorial:
  <a href="https://auth0.com/docs/integrations/aws-api-gateway/custom-authorizers/" rel="nofollow noreferrer">https://auth0.com/docs/integrations/aws-api-gateway/custom-authorizers/</a></p>
  
  <p>And this is my Authorization lambda code:</p>
  
  <p>Handler:</p>
  
  <pre><code>'use strict';
  
  let jwtManager = require("./jwt_manager");
  
  module.exports.authenticate = (event, context, callback) =&gt; {
  
    jwtManager.validate(event, function (error, data) {
      if (error) {
        if (!error) {
          context.fail("Unhandled error");
        }
        context.fail(error);
      }
      else {
        console.log("SUCCEED");
        context.succeed(data);
      }
    });
  
  };
  </code></pre>
  
  <p>And this is the jwtManager:</p>
  
  <pre><code>"use strict";
  require("dotenv").config({ silent: true });
  
  let jwksClient = require("jwks-rsa");
  let jwt = require("jsonwebtoken");
  
  module.exports.validate = function(params, callback) {
    var token = validateParams(params);
  
    var client = jwksClient({
      cache: true,
      rateLimit: true,
      jwksRequestsPerMinute: 10,
      jwksUri: process.env.JWKS_URI
    });
  
    var decodedJwt = jwt.decode(token, { complete: true });
    var kid = decodedJwt.header.kid;
  
    client.getSigningKey(kid, function(error, data) {
      if (error) {
          console.log(error);
        callback(error);
      } else {
        var signingKey = data.publicKey || data.rsaPublicKey;
        jwt.verify(
          token,
          signingKey,
          { audience: process.env.AUDIENCE, issuer: process.env.ISSUER },
          function(error, decoded) {
              if (error) {
                  console.log("ERROR");
                  console.log(error);
                  callback(error);
              }
              else {
                  console.log(decoded);
                  var response = {
                      principalId: decoded.sub,
                      policyDocument: getPolicyDocument("Allow", params.methodArn),
                      context: {
                          scope: decoded.scope
                      }
                  }
                  console.log(response);
                  console.log(response.policyDocument);
                  callback(null, response);
              }
          }
        );
      }
    });
  };
  
  function validateParams(params) {
    var token;
  
    if (!params.type || params.type !== "TOKEN") {
      throw new Error("Expected 'event.type' parameter to have value TOKEN");
    }
  
    var tokenString = params.authorizationToken;
    if (!tokenString) {
      throw new Error("Expected 'event.authorizationToken' parameter to be set");
    }
  
    var match = tokenString.match(/^Bearer (.*)$/);
    if (!match || match.length &lt; 2) {
      throw new Error(
        "Invalid Authorization token - '" +
          tokenString +
          "' does not match 'Bearer .*'"
      );
    }
  
    return match[1];
  }
  
   function getPolicyDocument(effect, resource) {
  
      var policyDocument = {};
      policyDocument.Version = '2012-10-17'; // default version
      policyDocument.Statement = [];
      var statementOne = {};
      statementOne.Action = [ 'execute-api:Invoke', 'lambda:Invoke'] ; // default action
      statementOne.Effect = effect;
      statementOne.Resource = resource.split('/')[0] + '/*';
      policyDocument.Statement[0] = statementOne;
      return policyDocument;
  }
  </code></pre>
  
  <p>Thanks in advance!</p>