I’ve below code to access model registered in AzureML. However, I’m receiving this error “CredentialUnavailableError: ManagedIdentityCredential authentication unavailable, no response from the IMDS endpoint.” when trying to access the model.
from azure.ai.ml import MLClient
from azure.identity import ManagedIdentityCredential
ml_client = MLClient(credential, subscription_id, resource_group, workspace_name)
print(f'ML Client :', ml_client)
azure = ml_client.models.list()
for model in azure:
print(model)
Note: I’ve created Role Assignment in all related services.
Nuzli Mohamad Anas is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
0
ManagedIdentityCredential authentication failed
According to this MS-Document
Both system and user managed identity is not supported with ManagedIdentityCredential
in the local environment.
The ManagedIdentityCredential
works only in Azure environments of services that support managed identity authentication.
In my azure environment, it worked successfully to list the Azure ML models.
Code:
from azure.ai.ml import MLClient
from azure.identity import DefaultAzureCredential,ManagedIdentityCredential
credential=credentials = ManagedIdentityCredential(client_id="d317xxxxxe2ba")
subscription_id="xxxxx0e43fec67"
resource_group="venkatesan-rg"
workspace_name="venkaxxxxce"
ml_client = MLClient(credential, subscription_id, resource_group, workspace_name)
print(f'ML Client :', ml_client)
azure = ml_client.models.list()
for model in azure:
print(model.name)
Output:
ML Client : MLClient(credential=<azure.identity._credentials.managed_identity.ManagedIdentityCredential object at 0x7f2674c7e590>, subscription_id=xxxx, resource_group_name=venkatesan-rg, workspace_name=venkxxxxpace)
model1
test
Code Text
You can use DefaultAzureCredential
for the code to work in both local and Azure environments as it will fall back to a few authentication options including managed identity.
Reference:
azure – Can a “User Assigned Managed Identity” be used locally? – Stack Overflow by Allen Wu