in below post my answer got's deleted.
How to get the attribute id by attribute code in magento 2
The accepted answer gets updated after my post so how you guys consider my answer as copied
You can see here in revision history https://magento.stackexchange.com/posts/226913/revisions
And for further note I checked that method in core and then answer
vendor/magento/module-eav/Model/ResourceModel/Entity/Attribute.php
In above file I checked getIdByCode
method and answered as its require two params