How to get Attribute id by product id Magento 2?

Get Attribute ids by the Product id in Magento 2 using Attribute Set Finder Interface.

Full Path of Interface:
Magento\Catalog\Api\AttributeSetFinderInterface

Get attribute set ids by product ids using method name findAttributeSetIdsByProductIds(array $productIds).  Pass Array of ids to fetch attribute id using the method.

Now If you want to find product id for the only single product,
You have to set SKU as array,
$sku = [’24-MB01′];
$result = $this->getAttributeIdbyProductIds($sku);

Output:
Array of attribute id of the product.