title: How to test API Gateway methods with custom authorizer and empty $context.authorizer.* variables?
body: <p>I have an API Gateway with a <code>POST</code> method that puts directly to a DynamoDB table. My method is also configured to use a custom authorizer via Lambda.</p>
  
  <p>In my template mapping I'm consuming some of the authorizer variables, such as <code>$context.authorizer.principalId</code> or <code>$context.authorizer.accountId</code>. Simplified template mapping looks as follows:</p>
  
  <pre><code>{ 
  "TableName": "$stageVariables.tableName",
  "Item": {
      "AccountId": {
          "S": "$context.authorizer.accountId"
          },
      "Id": {
          "S": "$context.requestId"
          },
      "Content": {
          "S": "$input.path('$.content')"
          },
      "UserId": {
          "S": "$context.authorizer.principalId"
          }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>Now, when I make an HTTP request to this API method deployed to a an actual stage, that request will go through the custom authorizer and provide / fill in all <code>$context.authorizer.*</code> variables in the template which might look like this:</p>
  
  <pre><code>{ 
  "TableName": "MyTable",
  "Item": {
      "AccountId": {
          "S": "12345"
          },
      "Id": {
          "S": "6fd5ff08-34c0-11e7-bf96-591a565835b3"
          },
      "Content": {
          "S": "my content"
          },
      "UserId": {
          "S": "userid-123456789"
          }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>When testing the API method via the API Gateway Test button, the test request is bypassing the custom authorizer (which makes sense, since authorizer can be tested separately) and produces a result like this:</p>
  
  <pre><code>{ 
  "TableName": "MyTable",
  "Item": {
      "AccountId": {
          "S": ""
          },
      "Id": {
          "S": "test-invoke-request"
          },
      "Content": {
          "S": "my content"
          },
      "UserId": {
          "S": ""
          }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>The following content is now invalid, since all fields get validated against the model, and getting the following validation error:</p>
  
  <pre><code>Endpoint response body before transformations: {"__type":"com.amazon.coral.validate#ValidationException","message":"One or more parameter values were invalid: An AttributeValue may not contain an empty string"}
  </code></pre>
  
  <hr>
  
  <p>Is there some way to specify authorizer variables when testing API Gateway methods?
  Or is there some smart way to define a fallback variable in the template mapping so that when it resolves to empty, it will fall back to, e.g., <code>test-invoke-principalid</code>, just like <code>$context.requestId</code> gets that out of the box?</p>
  
  <p>All I want is to be still able to use the API Gateway test feature while keeping all the validation / authorizer settings in place.</p>