title: Lambda Authorizer not returning proper error message with callback() in node.js
body: <p>I have created a Lambda Authorizer on a AWS API Gateway, which calls a Lambda Function. Following is the code in the Lambda Function written in Node.js 8.0 code.</p>
  
  <pre><code>exports.handler =  function(event, context, callback) {
      var token = event.authorizationToken;
      switch (token.toLowerCase()) {
          case 'allow':
              callback(null, generatePolicy('user', 'Allow', event.methodArn));
              break;
          case 'deny':
              callback(null, generatePolicy('user', 'Deny', event.methodArn));
              break;
          case 'unauthorized':
              callback("Unauthorized");   // Return a 401 Unauthorized response
              break;
          default:
              callback("Error: Invalid token"); 
      }
  };
  
  // Help function to generate an IAM policy
  var generatePolicy = function(principalId, effect, resource) {
      var authResponse = {};
  
      authResponse.principalId = principalId;
      if (effect &amp;&amp; resource) {
          var policyDocument = {};
          policyDocument.Version = '2012-10-17'; 
          policyDocument.Statement = [];
          var statementOne = {};
          statementOne.Action = 'execute-api:Invoke'; 
          statementOne.Effect = effect;
          statementOne.Resource = resource;
          policyDocument.Statement[0] = statementOne;
          authResponse.policyDocument = policyDocument;
      }
  
      // Optional output with custom properties of the String, Number or Boolean type.
      authResponse.context = {
          "stringKey": "stringval",
          "numberKey": 123,
          "booleanKey": true
      };
      return authResponse;
  }
  </code></pre>
  
  <p>(The above sample code if from the web site <a href="https://markpollmann.com/lambda-authorizer/" rel="nofollow noreferrer">https://markpollmann.com/lambda-authorizer/</a>)</p>
  
  <p>If I save and Test this function by passing an invalid value for authorizationToken, I get expected result which is below.</p>
  
  <pre><code>Response:
  {
    "errorMessage": "Error: Invalid token"
  }
  
  Request ID:
  "e93567c0-fcbb-4cb1-b0b3-28e9c1b30162"
  </code></pre>
  
  <p>But If I call this API from Postman, by passing the value in the header, I get the following response. I am getting this error for any value in the header i.e, deny, allow, unauthorized, wrong etc. </p>
  
  <pre><code>{
      "message": null
  }
  </code></pre>
  
  <p>The status message in postman shows "500 Internal Server Error". Following is the detail from header section in postman.</p>
  
  <pre><code>content-length →16
  content-type →application/json
  date →Fri, 08 Mar 2019 14:07:57 GMT
  status →500
  x-amz-apigw-id →W89kFDRDoEFxYg=
  x-amzn-errortype →AuthorizerConfigurationException
  x-amzn-requestid →92f31d11-41ab-11e9-9c36-97d38d96f31b
  </code></pre>
  
  <p>I do not understand why the API is returning the above response and error message, while the Lambda test is working fine. </p>
  
  <p>I have already gone through the following two threads in SO, but the answers/comments couldn't help in my case.</p>
  
  <p><a href="https://stackoverflow.com/questions/51187864/aws-api-gateway-with-custom-authorizer-returns-authorizerconfigurationexception">AWS API Gateway with custom authorizer returns AuthorizerConfigurationException</a>
  <a href="https://stackoverflow.com/questions/38626455/aws-api-gateway-custom-authorizer-authorizerconfigurationexception">AWS API Gateway Custom Authorizer AuthorizerConfigurationException</a></p>