python - 如何使用arm模板部署python azure函数?

标签 python azure azure-functions azure-rm-template

以下内容部署运行指定 C# 的 azure 函数。如何对应该运行 python 的函数执行相同的操作?

我尝试将名称更改为 __init__.py,就像在使用 azure-function-core-tools func 命令和 -- 时生成的那样python 开关,但甚至找不到错误消息来说明为什么事情不起作用。

{
    "$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "appName": {
            "type": "string",
            "metadata": {
                "description": "The name of the function app that you wish to create."
            }
        },
        "storageAccountType": {
            "type": "string",
            "defaultValue": "Standard_LRS",
            "allowedValues": [
                "Standard_LRS",
                "Standard_GRS",
                "Standard_ZRS",
                "Premium_LRS"
            ],
            "metadata": {
                "description": "Storage Account type"
            }
        }
    },
    "variables": {
        "functionAppName": "[parameters('appName')]",
        "hostingPlanName": "[parameters('appName')]",
        "storageAccountName": "[concat(uniquestring(resourceGroup().id), 'azfunctions')]"
    },
    "resources": [
        {
            "type": "Microsoft.Storage/storageAccounts",
            "name": "[variables('storageAccountName')]",
            "apiVersion": "2015-06-15",
            "location": "[resourceGroup().location]",
            "properties": {
                "accountType": "[parameters('storageAccountType')]"
            }
        },
        {
            "type": "Microsoft.Web/serverfarms",
            "apiVersion": "2015-04-01",
            "name": "[variables('hostingPlanName')]",
            "location": "[resourceGroup().location]",
            "properties": {
                "name": "[variables('hostingPlanName')]",
                "computeMode": "Dynamic",
                "sku": "Dynamic"
            }
        },
        {
            "apiVersion": "2015-08-01",
            "type": "Microsoft.Web/sites",
            "name": "[variables('functionAppName')]",
            "location": "[resourceGroup().location]",
            "kind": "functionapp",
            "properties": {
                "name": "[variables('functionAppName')]",
                "serverFarmId": "[resourceId('Microsoft.Web/serverfarms', variables('hostingPlanName'))]"
            },
            "dependsOn": [
                "[resourceId('Microsoft.Web/serverfarms', variables('hostingPlanName'))]",
                "[resourceId('Microsoft.Storage/storageAccounts', variables('storageAccountName'))]"
            ],
            "resources": [
                {
                    "apiVersion": "2016-03-01",
                    "name": "appsettings",
                    "type": "config",
                    "dependsOn": [
                        "[resourceId('Microsoft.Web/sites', variables('functionAppName'))]",
                        "[resourceId('Microsoft.Storage/storageAccounts', variables('storageAccountName'))]"
                    ],
                    "properties": {
                        "AzureWebJobsStorage": "[concat('DefaultEndpointsProtocol=https;AccountName=',variables('storageAccountName'),';AccountKey=',listkeys(resourceId('Microsoft.Storage/storageAccounts', variables('storageAccountName')), '2015-05-01-preview').key1,';')]",
                        "AzureWebJobsDashboard": "[concat('DefaultEndpointsProtocol=https;AccountName=',variables('storageAccountName'),';AccountKey=',listkeys(resourceId('Microsoft.Storage/storageAccounts', variables('storageAccountName')), '2015-05-01-preview').key1,';')]",
                        "FUNCTIONS_EXTENSION_VERSION": "latest"
                    }
                },
                {
                "apiVersion": "2015-08-01",
                "name": "TestFunctionCM",
                "type": "functions",
                "dependsOn": [
                    "[resourceId('Microsoft.Web/sites', variables('functionAppName'))]"
                ],
                "properties": {
                    "config": {
                    "bindings": [
                        {
                        "authLevel": "anonymous",
                        "name": "req",
                        "type": "httpTrigger",
                        "direction": "in"
                        },
                        {
                        "name": "res",
                        "type": "http",
                        "direction": "out"
                        }
                    ]
                  },
                  "files": {
                    "run.csx": "using System.Net;\r\n\r\n public static HttpResponseMessage Run(HttpRequestMessage req, TraceWriter log)\r\n\r\n {\r\n\r\nreturn req.CreateResponse(\"Hello from MyFunction\", HttpStatusCode.OK);\r\n\r\n }"
                  }
                }
              }
            ]
        }
    ]
}

谢谢。

最佳答案

您可能需要以下内容:

  1. appsettings 下的运行时

    “FUNCTIONS_WORKER_RUNTIME”:“python”

  2. 我的模板看起来有点不同,但确实部署了一个 python 函数,以下是来自同一函数的资源:

{
  "type": "Microsoft.Web/sites",
  "apiVersion": "2018-11-01",
  "name": "[parameters('name')]",
  "location": "[parameters('location')]",
  "dependsOn": [
    "microsoft.insights/components/mycoolfunction",
    "[concat('Microsoft.Web/serverfarms/', parameters('hostingPlanName'))]",
    "[concat('Microsoft.Storage/storageAccounts/', parameters('storageAccountName'))]"
  ],
  "tags": {},
  "kind": "functionapp,linux",
  "properties": {
    "name": "[parameters('name')]",
    "siteConfig": {
      "appSettings": [
        {
          "name": "FUNCTIONS_WORKER_RUNTIME",
          "value": "python"
        },
        {
          "name": "FUNCTIONS_EXTENSION_VERSION",
          "value": "~2"
        },
        {
          "name": "APPINSIGHTS_INSTRUMENTATIONKEY",
          "value": "[reference('microsoft.insights/components/mycoolfunction', '2015-05-01').InstrumentationKey]"
        },
        {
          "name": "AzureWebJobsStorage",
          "value": "[concat('DefaultEndpointsProtocol=https;AccountName=',parameters('storageAccountName'),';AccountKey=',listKeys(resourceId('Microsoft.Storage/storageAccounts', parameters('storageAccountName')), '2019-06-01').keys[0].value,';EndpointSuffix=','core.windows.net')]"
        }
      ]
    },
    "serverFarmId": "[concat('/subscriptions/', parameters('subscriptionId'),'/resourcegroups/', parameters('serverFarmResourceGroup'), '/providers/Microsoft.Web/serverfarms/', parameters('hostingPlanName'))]",
    "hostingEnvironment": "[parameters('hostingEnvironment')]",
    "clientAffinityEnabled": false
  }
}

关于python - 如何使用arm模板部署python azure函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58928612/

相关文章:

azure - Azure 函数槽是否需要应用程序设置 AzureWebJobsStorage?

powershell - 如何使用 powershell 轮询 kudu api 响应以获取部署状态

azure - 可以在一个功能应用程序中拥有多个 Durable 功能吗?

python - 如何安全地终止在多个 GPU 上运行的 TensorFlow 程序

Python PULP 不支持的操作数类型 TypeError

c# - 此请求的授权已被拒绝 - 桌面到 ASP.NET Web API

azure - Microsoft Azure 机器人类型选择

python - PyQT 与 PyObjc/Cocoa-Python 对比

python - Django和多线程程序中的 "get() returned more than one Model name"错误

azure - graph.windows.net 上的 SSL 错误