title: AppSync check if DynamoDB record exists
body: <p>I am trying to write a resolver for AppSync that derives the value for a Boolean field based on the existence of a record in DynamoDB.</p>
  
  <p>I currently have the following request mapping template:</p>
  
  <pre><code>{
      "version": "2017-02-28",
      "operation": "GetItem",
      "key": {
          "field1": $util.dynamodb.toDynamoDBJson($ctx.args.field1),
          "field2": $util.dynamodb.toDynamoDBJson($ctx.args.field2)
      }
  }
  </code></pre>
  
  <p>And the following response mapping template:</p>
  
  <pre><code>#if($util.isNull($ctx.result))
      #set($exists = false)
  #else
      #set($exists = true)
  #end
  
  $util.toJson({
      "field1": $ctx.args.field1,
      "field2": $ctx.args.field2,
      "exists": $exists
  })
  </code></pre>
  
  <p>This works correctly if the record exists but if it does not then AppSync simply returns "null" for the entire API call and does not seem to evaluate the response mapping template at all. Is there any way I can instruct it not to do this?</p>
  
  <p>Another option would be to perform a query and look at the length of the response but I have no idea how to check length in these templates.</p>