title: Custom response Lambda Authorizer for 401
body: <p>Calling the Lambda callback function from a Lambda Authorizer with the string <code>Unauthorized</code> in the error parameter returns a 401 response with the body:</p>
  <p><code>{ &quot;message&quot;: &quot;Unauthorized&quot; }</code></p>
  <p>Trying to use any other string in the response results in the response:</p>
  <p><code>{ &quot;message&quot;: null }</code></p>
  <p>If instead you return a Deny Policy Document in the result parameter of the callback, you'll get a 403 with the response something like:</p>
  <p><code>{ &quot;message&quot;: &quot;Unable to access resource with an explicit deny&quot; }</code></p>
  <p>After looking around it seems you need to configure a Gateway Response to return a custom response from a Lambda Authorizer, which I have working for the 403 response, but can't figure out how to do this for a 401.</p>
  <p>For the 403 I created a Gateway Response with the template:</p>
  <p><code>{\&quot;message\&quot;:\&quot;$context.authorizer.stringKey\&quot;}</code></p>
  <p>Then on the result object I set the following</p>
  <p><code>ResultObject.context.stringKey = 'My custom response'</code></p>
  <p>This works and is documented <a href="https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-lambda-authorizer-output.html" rel="noreferrer">here</a>.</p>
  <p>However, for the 401, because I am not returning a policy document I don't know how to use a custom response. I created the same Gateway Response as I did for the 403, but if I hit the callback with any string (other than 'Unauthorized') in the error param I get the null message. I can't return in the result param because this needs to be a response structure containing the Policy Document.</p>
  <p>Any ideas on how I can return a custom response with a 401?</p>