首页 > 解决方案 > 尝试为 Azure 函数部署事件网格订阅时出现 InvalidResourceNamespace 错误

问题描述

我有一个现有的事件网格主题,并希望使用现有的 Azure 函数端点向它添加一个事件订阅。

为此,我使用了链接模板。ARM 模板验证通过,但部署失败,出现一个非常奇怪的错误:

"InvalidResourceNamespace: "资源命名空间 'subscriptions' 无效。(代码:InvalidResourceNamespace)”

这是原始错误:

{
  "code": "DeploymentFailed",
  "message": "At least one resource deployment operation failed. Please list deployment operations for details. Please see https://aka.ms/DeployOperations for usage details.",
  "details": [
    {
      "code": "InvalidContentLink",
      "message": "Unable to download deployment content from 'https://storagearmtpl.blob.core.windows.net/arm-tpl-service-cd-11111-artifacts/nestedtemplates/eventGridSubscriptionTemplate.json?sv=sasartifactsstring'. The tracking Id is '11111111'. Please see https://aka.ms/arm-deploy for usage details."
    },
    {
      "code": "InvalidResourceNamespace",
      "message": "The resource namespace 'subscriptions' is invalid."
    }
  ]
}

sasartifactsstring有效的工件位置 sas 令牌在哪里。(我假设,它看起来是正确的)

我知道这个错误源于模板中资源的“类型”无效,但正如您在下面看到的,它只是Microsoft.EventGrid/topics/providers/eventSubscriptions.

/nestedtemplates/eventGridSubscriptionTemplate.json

{

    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
      "subscriptionName": {
        "type": "string",
        "metadata": {
          "description": "Name of the event grid subscription"
        }
      },
      "topicName": {
        "type": "string",
        "metadata": {
          "description": "Event grid Topic Name to Subscribe."
        }
      },
      "functionResourceGroupName": {
        "type": "string",
        "metadata": {
          "description": "Resource group name for functionapp"
        }
      },
      "functionAppName": {
        "type": "string",
        "metadata": {
          "description": "function app name"
        }
      },
      "subscriptionId": {
        "type": "string",
        "metadata": {
          "description": "The id string of the Azure subscription"
        }
      },
      "topicResourceGroupName": {
        "type": "string",
        "metadata": {
          "description": "The name of the topic resource group"
        }
      }
    },
    "variables": {},
    "resources": [
      {
        "name": "[concat(parameters('topicName'), '/Microsoft.EventGrid/', parameters('subscriptionName'))]",
        "type": "Microsoft.EventGrid/topics/providers/eventSubscriptions",
        "location": "[resourceGroup().location]",
        "apiVersion": "2020-06-01",
        "properties": {
          "topic": "[concat('/subscriptions/', parameters('subscriptionId'), '/resourceGroups/', parameters('topicResourceGroupName'), 'providers/Microsoft.EventGrid/topics/', parameters('topicName'))]",
          "destination": {
                  "endpointType": "AzureFunction",
                  "properties": {
                      "resourceId": "[concat('/subscriptions/', parameters('subscriptionId'), '/resourceGroups/', parameters('functionResourceGroupName'), '/providers/Microsoft.Web/sites/', parameters('functionAppName'), '/functions/HelloWorld')]",
                      "maxEventsPerBatch": 1,
                      "preferredBatchSizeInKilobytes": 64
                  }
              },
          }
        },
        "dependsOn": [
        ]
      }
    ],
    "outputs": {}
  }

/azuredeploy.json

{
  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "_artifactsLocation": {
      "type": "string"
    },
    "_artifactsLocationSasToken": {
      "type": "securestring"
    },
    "functionResourceGroupName": {
      "type": "string"
    },
    "functionAppName": {
      "type": "string"
    },
    "topicName": {
      "type": "string"
    },
    "topicResourceGroupName": {
      "type": "string"
    },
    "subscriptionId": {
      "type": "string"
    }
   },
   "variables": {
     "templateFolder": "nestedtemplates",
     "subscriptionTemplateFileName": "eventGridSubscriptionTemplate.json"
   },
   "resources": [
   {
     "name": "functionsubscription"
     "type": "Microsoft.Resources/deployments",
     "apiVersion": "2017-05-10"
     "resourceGroup": "[parameters('topicResourceGroupName')]",
      "dependsOn": [ ],
      "properties": {
        "mode": "Incremental",
        "templateLink": {
          "uri": "[concat(parameters('_artifactsLocation'), '/', variables('templateFolder'), '/', variables('subscriptionTemplateFileName'), parameters('_artifactsLocationSasToken'))]",
          "contentVersion": "1.0.0.0"
        },
        "parameters": {
          "subscriptionName": {
            "value": "FunctionSubscription"
          },
          "topicName": {
            "value": "[parameters('topicName')]" 
          },
          "functionResourceGroupName": {
            "value": "[parameters('functionResourceGroupName')]"
          },
          "functionAppName": {
            "value": "[parameters('functionAppName')]"
          },
          "topicResourceGroupName": {
            "value": "[parameters('topicResourceGroupName')]"
          },
          "subscriptionId": {
            "value": "[parameters('subscriptionId')]"
          }
        }
      }
    }
   
]
}
   

天蓝色部署参数文件

{
  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
  ,
    "functionResourceGroupName": {
      "value": "functionResourceGroup"
    },
    "functionAppName": {
      "value": "functionAppName"
    },
    "subscriptionId": {
      "value": "1111111111"
    },
    "topicName": {
      "value": "topicName"
    },
    "topicResourceGroupName": {
      "value": "topicResourceGroup"
    }
  }

真的不确定我在这里做错了什么。值得注意的是,第一个错误也很烦人,我不确定为什么它不能下载部署内容......

更新/编辑: 值得注意的是,该版本使用的是经典 Azure 发布管道。并且在发布期间出现错误。

查看资源组的部署日志,我能够看到部署正在尝试部署无效资源,类型以“subscriptions/.....”开头,所以至少我知道错误出在哪里从。仍在调查导致这种误读的原因......

标签: azurearm-templateazure-eventgrid

解决方案


奇怪的“订阅”错误的原因是我在我的部署(父)ARM 模板的资源列表中插入了一个新资源,但不是在列表的末尾。

一旦我将引用新事件网格订阅的部署资源放在资源列表的末尾,错误就没有出现。

天蓝色部署.json

resources: [
  {all other existing deployment resources ....},
  {
     "name": "functionsubscription"
     "type": "Microsoft.Resources/deployments",
     "apiVersion": "2017-05-10"
     "resourceGroup": "[parameters('topicResourceGroupName')]",
      "dependsOn": [ ],
      "properties": {
        "mode": "Incremental",
        "templateLink": {
          "uri": "[concat(parameters('_artifactsLocation'), '/', variables('templateFolder'), '/', variables('subscriptionTemplateFileName'), parameters('_artifactsLocationSasToken'))]",
          "contentVersion": "1.0.0.0"
        },
        "parameters": {
          "subscriptionName": {
            "value": "FunctionSubscription"
          },
          "topicName": {
            "value": "[parameters('topicName')]" 
          },
          "functionResourceGroupName": {
            "value": "[parameters('functionResourceGroupName')]"
          },
          "functionAppName": {
            "value": "[parameters('functionAppName')]"
          },
          "topicResourceGroupName": {
            "value": "[parameters('topicResourceGroupName')]"
          },
          "subscriptionId": {
            "value": "[parameters('subscriptionId')]"
          }
        }
      }
    }
]

但是,我仍在处理 InvalidContentLink 错误,问题的主要问题已经解决。


推荐阅读