ARM Template to deploy ‘Media Service’ and ‘Azure Video Analyzer for Media’ fails with error: AMS_UNREACHABLE

Johan Klijn 41 Reputation points
2022-04-01T12:56:55.867+00:00

I want to create a single ARM Template which deploys an working ‘Azure Video Analyzer for Media’. I started with the example template on https://learn.microsoft.com/en-us/azure/azure-video-analyzer/video-analyzer-for-media-docs/deploy-with-arm-template, but that template requires an existing Azure Media Service. So I added the declaration of the Media Service to the ARM Template so I have a single ARM Template which deploys an ‘Azure Video Analyzer for Media’ with all it dependencies/requirements. Unfortunately often the deployment fails with the error:

The deployment 'azuredeploy' failed with error(s). Showing 1 out of 1 error(s). Status Message: Failed to connect to Media Services account 'mspjkn1t0253ewo7f75fswg'. Trace id: 'd4132dae-0f1e-4681-beb2-bfd950bed601'. Trace id: 'd4132dae-0f1e-4681-beb2-bfd950bed601 (Code:AMS_UNREACHABLE) CorrelationId: d4132dae-0f1e-4681-beb2-bfd950bed601

I thought the issue could be that the Media Service is not fully functional/available, so I added a deploymentScript to the AMR Template which keeps running until it’s able to retrieve the assets from the Media Service. But although the script is eventually able to retrieve the assets, the ARM Template deployment still fails with AMS_UNREACHABLE error.

Any recommendation how to create an ARM Template which deploys an ‘Azure Video Analyzer for Media’ with all it dependencies/requirements?

The ARM Template I use:

{  
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",  
  "contentVersion": "1.0.0.0",  
  "parameters": {  
    "environment_name": {  
      "defaultValue": "t01",  
      "type": "String"  
    },  
    "utcValue": {  
      "type": "string",  
      "defaultValue": "[utcNow()]"  
    }  
  },  
  "variables": {  
    "location": "[resourceGroup().location]",  
    "product_name": "pjkn1",  
    "videoIndexerName": "[concat('vi', variables('product_name'), parameters('environment_name'), uniqueString(subscription().subscriptionId))]",  
    "mediaServiceName": "[concat('ms', variables('product_name'), parameters('environment_name'), uniqueString(subscription().subscriptionId))]",  
    "storageAccountNameVideoIndexer": "[toLower(concat('st', variables('product_name'), parameters('environment_name'), uniqueString(subscription().subscriptionId)))]",  
    "userAssignedIdentityName": "[toLower(concat('man-id-', variables('product_name'), '-', parameters('environment_name'), uniqueString(subscription().subscriptionId)))]",  
    "roleDefinitionId": "[concat('/subscriptions/', subscription().subscriptionId, '/providers/Microsoft.Authorization/roleDefinitions/', 'b24988ac-6180-42a0-ab88-20f7382dd24c')]",  
    "roleAssignmentName": "[guid(subscription().subscriptionId, resourceGroup().name, variables('storageAccountNameVideoIndexer'), variables('userAssignedIdentityName'))]",  
    "mediaServiceReachableDeploymentScriptName": "msReachableScript",  
    "resourceTags": {  
      "Environment": "[parameters('environment_name')]",  
      "Product": "[variables('product_name')]"  
    }  
  },  
  "resources": [  
    {  
      "type": "Microsoft.Resources/deploymentScripts",  
      "apiVersion": "2020-10-01",  
      "name": "[variables('mediaServiceReachableDeploymentScriptName')]",  
      "location": "[resourceGroup().location]",  
      "kind": "AzureCLI",  
      "identity": {  
          "type": "userAssigned",  
          "userAssignedIdentities": {  
            "[resourceId('Microsoft.ManagedIdentity/userAssignedIdentities', variables('userAssignedIdentityName'))]": {}  
          }  
      },        
      "properties": {  
        "forceUpdateTag": "[parameters('utcValue')]",  
        "AzCliVersion": "2.15.0",  
        "scriptContent": "  
            echo $1 $2  
            echo \"resourceGroup: $resourceGroup\"  
            echo \"mediaServiceName: $mediaServiceName\"  
            sleepingTime=5  
            maxWaittime=600 #wait max 10 minutes for the Media Service to become available.  
            stopChecking=0  
            mediaServiceReachable=0  
            counter=0  
  
            echo \"Validating if Media Service $mediaServiceName in resource group $resourceGroup is available...\"  
  
            while [ $stopChecking -eq 0 ]; do  
                echo \"stopChecking: $stopChecking\"  
                  
                timeSlept=$(($counter * $sleepingTime))  
  
                endpoints=$(az ams streaming-endpoint list -g $resourceGroup -a $mediaServiceName)   
                echo \"Error code: '${?}'\"  
                echo \"endpoints: '$endpoints'\"  
                  
                if [[ ${?} -eq 0 ]] && [[ ! -z $endpoints ]]; then          
                    mediaServiceReachable=1  
                    stopChecking=1                       
                else  
                  echo \"Media Service unreachable after $timeSlept seconds (Max wait time: $maxWaittime). Waiting $sleepingTime seconds for next check...\"  
                    sleep $sleepingTime  
                fi  
                  
                counter=$(($counter + 1))  
                if [ $timeSlept -gt $maxWaittime ]; then  
                    stopChecking=1  
                fi  
            done     
  
            if [ $mediaServiceReachable -eq 1 ]; then  
                echo \"Media Service reachable.\"  
            else  
                echo \"Stopped checking if the Media Service is reachable.\"  
            fi        
        ",  
        "environmentVariables": [  
          {  
            "name": "resourceGroup",  
            "value": "[ resourceGroup().name]"  
          },  
          {  
            "name": "mediaServiceName",  
            "secureValue": "[variables('mediaServiceName')]"  
          }  
        ],          
        "arguments": "",  
        "timeout": "PT15M",  
        "cleanupPreference": "OnSuccess",  
        "retentionInterval": "PT3H"  
      },  
      "dependsOn": [  
        "[resourceId('Microsoft.Media/mediaservices', variables('mediaServiceName'))]"  
      ]  
    },  
    {  
      "type": "Microsoft.ManagedIdentity/userAssignedIdentities",  
      "name": "[variables('userAssignedIdentityName')]",  
      "apiVersion": "2018-11-30",  
      "tags": "[variables('resourceTags')]",  
      "location": "[variables('location')]"  
    },  
    {  
      "type": "Microsoft.Authorization/roleAssignments",  
      "apiVersion": "2020-04-01-preview",  
      "name": "[variables('roleAssignmentName')]",  
      "properties": {  
        "roleDefinitionId": "[variables('roleDefinitionId')]",  
        "principalId": "[reference(resourceId('Microsoft.ManagedIdentity/userAssignedIdentities', variables('userAssignedIdentityName')), '2018-11-30').principalId]",  
        "principalType": "ServicePrincipal"  
      },  
      "scope": "[concat('Microsoft.Media/mediaservices', '/', variables('mediaServiceName'))]",  
      "dependsOn": [  
        "[resourceId('Microsoft.ManagedIdentity/userAssignedIdentities', variables('userAssignedIdentityName'))]",  
        "[resourceId('Microsoft.Resources/deploymentScripts', variables('mediaServiceReachableDeploymentScriptName'))]"  
      ]  
    },  
    {  
      "type": "Microsoft.Storage/storageAccounts",  
      "apiVersion": "2019-06-01",  
      "name": "[variables('storageAccountNameVideoIndexer')]",  
      "location": "[variables('location')]",  
      "tags": "[variables('resourceTags')]",  
      "sku": {  
        "name": "Standard_LRS",  
        "tier": "Standard"  
      },  
      "kind": "StorageV2",  
      "properties": {  
        "allowBlobPublicAccess": false  
      }  
    },  
    {  
      "type": "Microsoft.Media/mediaservices",  
      "apiVersion": "2020-05-01",  
      "name": "[variables('mediaServiceName')]",  
      "location": "[variables('location')]",  
      "properties": {  
        "storageAccounts": [  
          {  
            "id": "[resourceId('Microsoft.Storage/storageAccounts', variables('storageAccountNameVideoIndexer'))]",  
            "type": "Primary"  
          }  
        ]  
      },  
      "dependsOn": [  
        "[resourceId('Microsoft.Storage/storageAccounts', variables('storageAccountNameVideoIndexer'))]"  
      ]  
    },  
    {  
      "type": "Microsoft.VideoIndexer/accounts",  
      "apiVersion": "2021-11-10-preview",  
      "name": "[variables('videoIndexerName')]",  
      "tags": "[variables('resourceTags')]",  
      "location": "[variables('location')]",  
      "identity": {  
        "type": "UserAssigned",  
        "userAssignedIdentities": {  
          "[resourceId('Microsoft.ManagedIdentity/userAssignedIdentities', variables('userAssignedIdentityName'))]": {}  
        }  
      },  
      "properties": {  
        "mediaServices": {  
          "resourceId": "[resourceId('Microsoft.Media/mediaservices', variables('mediaServiceName'))]",  
          "userAssignedIdentity": "[resourceId('Microsoft.ManagedIdentity/userAssignedIdentities', variables('userAssignedIdentityName'))]"  
        }  
      },  
      "dependsOn": [  
        "[resourceId('Microsoft.Media/mediaservices', variables('mediaServiceName'))]",  
        "[resourceId('Microsoft.ManagedIdentity/userAssignedIdentities', variables('userAssignedIdentityName'))]",  
        "[resourceId('Microsoft.Resources/deploymentScripts', variables('mediaServiceReachableDeploymentScriptName'))]"  
      ]  
    }  
  ],  
  "outputs": {  
    "videoIndexerAccountId": {  
      "type": "string",  
      "value": "[reference(resourceId('Microsoft.VideoIndexer/accounts', variables('videoIndexerName'))).accountId]"  
    }  
  }  
}  
Azure Media Services
Azure Media Services
A group of Azure services that includes encoding, format conversion, on-demand streaming, content protection, and live streaming services.
292 questions
{count} votes