You can also use Magento\Catalog\Api\ProductAttributeRepositoryInterface and inject it into your class.
You can use the "get" method of the repository class. This works for me even if I supplied an attribute_id instead of the attribute_code. I've tested it in 2.2.6.
class Items extends \Magento\Framework\View\Element\Template{
protected $repository;
public function __construct(
\Magento\Catalog\Api\ProductAttributeRepositoryInterface $repository
){
$this->repository = $repository;
}
public function test($attributeId){
$attribute = $this->repository->get($attributeId);
}
}