Insert custom ID into wp_get_attachment_link

You have to supply a argument count when adding the filter callback, and add the arguments you are expecting to receive to your callback function. Looking at the wp_get_attachment_link source you can tell that 6 arguments is supplied when applying the filters (the link markup and $id, $size, $permalink, $icon, $text). Here’s how you could would do just that:

add_filter('wp_get_attachment_link', 'add_id_into_link', 10, 6);
function add_id_into_link($link, $id = null, $size = null, $permalink = null, $icon = null, $text = null) {
    return str_replace('<a href', '<a id="'. $id .'" href', $link);
}