How do I create an ajax link?
Your code is missing one part that I can see, the #attached key:

  $build['ajax_edit_link'] = array(
    '#theme' =&gt; 'links',
    '#weight' =&gt; -2,
    '#links' =&gt; array(
      'ajax_edit_link' =&gt; array(
        'title' =&gt; t('Edit'),
        'url' =&gt; $entity-&gt;urlInfo('edit-form'),
        'attributes' =&gt; array(
          'class' =&gt; array('use-ajax'),
          'data-dialog-type' =&gt; 'dialog'
          'data-dialog-options' =&gt; Json::encode(array(
            'width' =&gt; 1200,
            'height' =&gt; 500,
          ))
        ),
      ),
    ),
    '#attached' =&gt; array('library' =&gt; array('core/drupal.ajax')),
  );