简体   繁体   English

使用 ARM 创建 Azure Function 主机密钥不适用于新部署

[英]Creating an Azure Function host key using ARM doesn't work on a new deployment

I try to create an Azure Function host key inside an ARM template where I first create the function, and then I create the key:我尝试在首先创建函数的ARM模板中创建 Azure 函数主机密钥,然后创建密钥:

{
  "type": "Microsoft.Web/sites/host/functionKeys",
  "apiVersion": "2018-11-01",
  "name": "[concat(parameters('FUNCTIONNAME'), '/default/test-key')]",
  "properties": {
    "name": "test-key",
    "value": "test-value"
  },
  "dependsOn": [
    "[resourceId('Microsoft.Web/sites', parameters('FUNCTIONNAME'))]"
  ]
}

It looks like, that the deployment will add the host key test-key when the function is already deployed.看起来,当函数已经部署时,部署将添加主机密钥test-key If I deploy the template to a new resource group, the host key is not created.如果我将模板部署到新资源组,则不会创建主机密钥。 If I run the deployment a second time, it is.如果我第二次运行部署,它是。

Is there anything wrong with my dependsOn declaration?我的dependsOn声明有什么问题吗? Any other ideas?还有其他想法吗?

There are several issues with the deployment of functionkeys within ARM templates.在 ARM 模板中部署功能键存在几个问题。 Your code is correct and as you said, it successfully deploys sometimes.您的代码是正确的,正如您所说,它有时会成功部署。 Without having deep knowledge of what really happens under the hood, here some of my (painful) learnings:在没有深入了解幕后真正发生的事情的情况下,这里是我的一些(痛苦的)学习:

  • Keys are not created before the function's content is somehow materialized (maybe it has to look if there are functions with HttpTrigger).在函数的内容以某种方式具体化之前不会创建键(也许它必须查看是否有带有 HttpTrigger 的函数)。 So the behavior depends on the way the code is provided - with linked sourcecontrol (eg Github) I had the biggest problems vs. WEBSITE_RUN_FROM_PACKAGE works pretty well.所以行为取决于提供代码的方式 - 使用链接的源代码控制(例如 Github),我遇到了最大的问题,而 WEBSITE_RUN_FROM_PACKAGE 工作得很好。 When you setup sourcecontrol in ARM template too, you can add a dependsOn for the functionKeys resource like "[resourceId('Microsoft.Web/sites/sourcecontrols', 'name of function', 'web')]" .当您也在 ARM 模板中设置源代码控制时,您可以为 functionKeys 资源添加一个依赖项,例如"[resourceId('Microsoft.Web/sites/sourcecontrols', 'name of function', 'web')]" With that, I achieved that the functionkeys are deployed also on complete initial deployments有了这个,我实现了功能键也部署在完整的初始部署中

  • You may have race conditions when you try to read the deployed functionKeys in the same ARM template (eg for usage in API Management).当您尝试在同一 ARM 模板中读取已部署的 functionKeys 时,您可能会遇到竞争条件(例如,用于 API 管理)。 You can and should set up a dependsOn with "[resourceId('Microsoft.Web/sites/host/functionKeys', 'name of function', 'default', 'name of key')]" which may help in some situations.您可以并且应该使用"[resourceId('Microsoft.Web/sites/host/functionKeys', 'name of function', 'default', 'name of key')]"设置一个dependsOn,这在某些情况下可能会有所帮助。 But I also had the situation where the key wasn't yet ready to be read and I ended up with a subsequent deployment run for this.但我也遇到过密钥尚未准备好读取的情况,我最终为此进行了后续部署。 What you can try is to chain it with some "dependsOn" settings so that it is executed as late as possible (well, this is rather a hack).您可以尝试的是将它与一些“dependsOn”设置链接起来,以便尽可能晚地执行它(好吧,这是一种黑客攻击)。

  • When you don't specify a value for the function key (like test-value in your snippet), a new value is generated on every deployment.如果您没有为功能键指定值(如代码片段中的test-value ),则每次部署都会生成一个新值。 So it is not really 'incremental' as it should be IMHO.所以它并不是真正的“增量”,因为它应该是恕我直言。 In combination with a delayed availability of the key as described above, I had the problem that I always got an old version of the key-value on subsequent deployments which was a bit painful to find out.结合上述密钥的延迟可用性,我遇到了一个问题,即我在后续部署中总是得到旧版本的键值,这有点让人痛苦。

  • If you think why not use the predefined master or default key to avoid these troubles: I often encountered the strange situation that the master and default key changed during the deployment.如果您想为什么不使用预定义的主密钥或默认密钥来避免这些麻烦:我经常遇到在部署过程中主密钥和默认密钥发生变化的奇怪情况。 So again the referencing component in the ARM template got served with an obsolete value of the key.因此,ARM 模板中的引用组件再次获得了一个过时的键值。

Hope these experiences help.希望这些经验有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ARM部署:获取Azure Function API密钥 - ARM Deployment: Get Azure Function API Key 使用 ARM 模板创建 Azure Function 密钥失败 - Creating Azure Function Key using ARM template fails Azure- 函数应用的 zip 推送部署不起作用 - Azure- zip push deployment for a function app doesn't work Azure Function 服务总线触发器在部署后不起作用 - Azure Function Service Bus Trigger Doesn't Work After the Deployment 通过ARM模板设置Azure主机/功能密钥 - Set Azure Host/Function Key via ARM Template 在Azure上部署后授权不起作用 - Authorization doesn't work after deployment on azure 从 Azure DevOps 进行新的 ARM 部署后删除了 Azure 函数代码 - Azure Function code deleted after a new ARM deployment from Azure DevOps 如何使用 ARM 模板为 Azure 功能中的部署槽添加默认 function 密钥 - How to add a default function key with ARM template for a deployment slot in Azure Functions Azure App Service连续部署Webhook不起作用 - Azure App Service Continuous Deployment Webhook doesn't work Set命令不适用于Azure Kubernetes群集中的部署更新 - Set command doesn't work for the deployment update in Azure Kubernetes cluster
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM