Search code examples
azure-cli

Azure cli - Failed to connect to MSI


How do I solve this error?

az account get-access-token --resource https://cognitiveservices.azure.com                                        
Failed to connect to MSI. Please make sure MSI is configured correctly.
Get Token request returned: <Response [400]>

Solution

  • When I ran same command as you in Azure Cloud Shell, I got same error as below:

    az account get-access-token --resource https://cognitiveservices.azure.com  
    

    Response:

    enter image description here

    To resolve the error, you need to run az login first and connect with vaild identity(user account) like below:

    az login --only-show-errors
    

    Response:

    enter image description here

    When I ran below command again after signing in with valid user account, I got access token successfully like this:

    az account get-access-token --resource https://cognitiveservices.azure.com
    

    Response:

    enter image description here

    I executed the same commands in my local environment too and got an access token successfully like below:

    az login
    az account show
    az account get-access-token --resource https://cognitiveservices.azure.com
    

    Response:

    enter image description here

    In your case, check how you are connecting to Azure from CLI and make sure to sign in with valid identity while running az login.