Azure 为什么ARM模板要创建单独的应用程序服务计划?

Azure 为什么ARM模板要创建单独的应用程序服务计划?,azure,azure-resource-manager,Azure,Azure Resource Manager,我想了解为什么创建了整个应用程序服务计划,而不仅仅是azure功能和应用程序洞察: 如果不强制创建应用程序服务计划,是否无法创建Azure Function应用程序? 在不创建应用服务计划组件的情况下,如何使用ARM模板创建Azure功能? 以下是我的完整模板: { "$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", "contentVersi

我想了解为什么创建了整个应用程序服务计划,而不仅仅是azure功能和应用程序洞察:

如果不强制创建应用程序服务计划,是否无法创建Azure Function应用程序?

在不创建应用服务计划组件的情况下,如何使用ARM模板创建Azure功能?

以下是我的完整模板:

{
    "$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "location": {
            "type": "string"
        },
        "storageAccountName": {
            "type": "string"
        },
        "accountType": {
            "type": "string"
        },
        "appName": {
            "type": "string"
        }
    },
    "variables": {
        "storageAccessTier": "Hot",
        "storageKind": "StorageV2",
        "supportsHttpsTrafficOnly": true,
        "functionAppName": "[parameters('appName')]",
        "applicationInsightsName": "[parameters('appName')]",
        "storageAccountName": "[parameters('storageAccountName')]",
        "storageAccountid": "[concat(resourceGroup().id,'/providers/','Microsoft.Storage/storageAccounts/', variables('storageAccountName'))]"
    },
    "resources": [
        {
            "name": "[variables('storageAccountName')]",
            "type": "Microsoft.Storage/storageAccounts",
            "apiVersion": "2018-07-01",
            "location": "[parameters('location')]",
            "properties": {
                "accessTier": "[variables('storageAccessTier')]",
                "supportsHttpsTrafficOnly": "[variables('supportsHttpsTrafficOnly')]"
            },
            "dependsOn": [],
            "sku": {
                "name": "[parameters('accountType')]"
            },
            "kind": "[variables('storageKind')]"
        },
        {
            "apiVersion": "2015-08-01",
            "type": "Microsoft.Web/sites",
            "name": "[variables('functionAppName')]",
            "location": "[parameters('location')]",
            "kind": "functionapp",
            "dependsOn": [
                "[resourceId('Microsoft.Storage/storageAccounts', variables('storageAccountName'))]"
            ],
            "properties": {
                "siteConfig": {
                    "appSettings": [
                        {
                            "name": "AzureWebJobsDashboard",
                            "value": "[concat('DefaultEndpointsProtocol=https;AccountName=', variables('storageAccountName'), ';AccountKey=', listKeys(variables('storageAccountid'),'2015-05-01-preview').key1)]"
                        },
                        {
                            "name": "AzureWebJobsStorage",
                            "value": "[concat('DefaultEndpointsProtocol=https;AccountName=', variables('storageAccountName'), ';AccountKey=', listKeys(variables('storageAccountid'),'2015-05-01-preview').key1)]"
                        },
                        {
                            "name": "WEBSITE_CONTENTAZUREFILECONNECTIONSTRING",
                            "value": "[concat('DefaultEndpointsProtocol=https;AccountName=', variables('storageAccountName'), ';AccountKey=', listKeys(variables('storageAccountid'),'2015-05-01-preview').key1)]"
                        },
                        {
                            "name": "WEBSITE_CONTENTSHARE",
                            "value": "[toLower(variables('functionAppName'))]"
                        },
                        {
                            "name": "FUNCTIONS_EXTENSION_VERSION",
                            "value": "~1"
                        },
                        {
                            "name": "WEBSITE_NODE_DEFAULT_VERSION",
                            "value": "6.5.0"
                        },
                        {
                            "name": "APPINSIGHTS_INSTRUMENTATIONKEY",
                            "value": "[reference(resourceId('microsoft.insights/components/', variables('applicationInsightsName')), '2015-05-01').InstrumentationKey]"
                        }
                    ]
                }
            }
        },
        {
            "apiVersion": "2018-05-01-preview",
            "name": "[variables('applicationInsightsName')]",
            "type": "microsoft.insights/components",
            "location": "[parameters('location')]",
            "tags": {
                "[concat('hidden-link:', resourceGroup().id, '/providers/Microsoft.Web/sites/', variables('applicationInsightsName'))]": "Resource"
            },
            "properties": {
                "ApplicationId": "[variables('applicationInsightsName')]",
                "Request_Source": "IbizaWebAppExtensionCreate"
            }
        }
    ],
    "outputs": {}
}

Azure功能需要应用程序服务计划才能运行,因此没有应用程序服务计划,您无法真正创建Azure功能


您可以将新的Azure功能附加到现有的应用程序服务计划,仅此而已。

您可能会错过模板中的
serverFarmId
。尝试下面的模板,它不会创建单独的应用程序服务计划,在我的示例中,它将功能应用程序附加到现有的应用程序服务计划
joyplan
和存储帐户
joystoragev1
,创建app insight
joytestfunsight
,并附加到它

样本:

{
    "$schema": "http://schema.management.azure.com/schemas/2014-04-01-preview/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "name": {
            "type": "String"
        },
        "storageName": {
            "type": "String"
        },
        "hostingPlanName": {
            "type": "String"
        },
        "location": {
            "type": "String"
        },
        "serverFarmResourceGroup": {
            "type": "String"
        },
        "subscriptionId": {
            "type": "String"
        }
    },
    "resources": [
        {
            "type": "Microsoft.Web/sites",
            "kind": "functionapp",
            "name": "[parameters('name')]",
            "apiVersion": "2016-03-01",
            "location": "[parameters('location')]",
            "properties": {
                "siteConfig": {
                    "appSettings": [
                        {
                            "name": "FUNCTIONS_WORKER_RUNTIME",
                            "value": "dotnet"
                        },
                        {
                            "name": "AzureWebJobsStorage",
                            "value": "[concat('DefaultEndpointsProtocol=https;AccountName=',parameters('storageName'),';AccountKey=',listKeys(resourceId('b83c1ed3-c5b6-44fb-b5ba-2b83a074c23f','joywebapp','Microsoft.Storage/storageAccounts', parameters('storageName')), '2015-05-01-preview').key1)]"
                        },
                        {
                            "name": "FUNCTIONS_EXTENSION_VERSION",
                            "value": "~2"
                        },
                        {
                            "name": "WEBSITE_NODE_DEFAULT_VERSION",
                            "value": "8.11.1"
                        },
                        {
                            "name": "APPINSIGHTS_INSTRUMENTATIONKEY",
                            "value": "[reference('microsoft.insights/components/joytestfuninsight', '2015-05-01').InstrumentationKey]"
                        }
                    ],
                    "alwaysOn": true
                },
                "name": "[parameters('name')]",
                "clientAffinityEnabled": false,
                "serverFarmId": "[concat('/subscriptions/', parameters('subscriptionId'),'/resourcegroups/', parameters('serverFarmResourceGroup'), '/providers/Microsoft.Web/serverfarms/', parameters('hostingPlanName'))]"
            },
            "dependsOn": [
                "microsoft.insights/components/joytestfuninsight"
            ]
        },
        {
            "type": "microsoft.insights/components",
            "name": "joytestfuninsight",
            "apiVersion": "2015-05-01",
            "location": "eastus",
            "properties": {
                "ApplicationId": "[parameters('name')]",
                "Request_Source": "IbizaWebAppExtensionCreate"
            }
        }
    ]
}
{
    "$schema": "http://schema.management.azure.com/schemas/2014-04-01-preview/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "name": {
            "type": "String"
        },
        "storageName": {
            "type": "String"
        },
        "location": {
            "type": "String"
        },
        "subscriptionId": {
            "type": "String"
        }
    },
    "resources": [
        {
            "type": "Microsoft.Web/sites",
            "kind": "functionapp",
            "name": "[parameters('name')]",
            "apiVersion": "2016-03-01",
            "location": "Central US",
            "properties": {
                "siteConfig": {
                    "appSettings": [
                        {
                            "name": "FUNCTIONS_WORKER_RUNTIME",
                            "value": "dotnet"
                        },
                        {
                            "name": "AzureWebJobsStorage",
                            "value": "[concat('DefaultEndpointsProtocol=https;AccountName=',parameters('storageName'),';AccountKey=',listKeys(resourceId('b83c1ed3-xxxxxxxxxxx-2b83a074c23f','joywebapp','Microsoft.Storage/storageAccounts', parameters('storageName')), '2015-05-01-preview').key1)]"
                        },
                        {
                            "name": "FUNCTIONS_EXTENSION_VERSION",
                            "value": "~2"
                        },
                        {
                            "name": "WEBSITE_CONTENTAZUREFILECONNECTIONSTRING",
                            "value": "[concat('DefaultEndpointsProtocol=https;AccountName=',parameters('storageName'),';AccountKey=',listKeys(resourceId('b83c1ed3-xxxxxxxxxxx-2b83a074c23f','joywebapp','Microsoft.Storage/storageAccounts', parameters('storageName')), '2015-05-01-preview').key1)]"
                        },
                        {
                            "name": "WEBSITE_CONTENTSHARE",
                            "value": "[concat(toLower(parameters('name')), 'b32d')]"
                        },
                        {
                            "name": "WEBSITE_NODE_DEFAULT_VERSION",
                            "value": "8.11.1"
                        },
                        {
                            "name": "APPINSIGHTS_INSTRUMENTATIONKEY",
                            "value": "[reference('microsoft.insights/components/joytest11insight', '2015-05-01').InstrumentationKey]"
                        }
                    ]
                },
                "name": "[parameters('name')]",
                "clientAffinityEnabled": false,
                "reserved": false
            },
            "dependsOn": [
                "microsoft.insights/components/joytest11insight"
            ]
        },
        {
            "type": "microsoft.insights/components",
            "name": "joytest11insight",
            "apiVersion": "2015-05-01",
            "location": "eastus",
            "properties": {
                "ApplicationId": "[parameters('name')]",
                "Request_Source": "IbizaWebAppExtensionCreate"
            }
        }
    ]
}
我的测试参数:

{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "name": {
            "value": "joytestfun"
        },
        "storageName": {
            "value": "joystoragev1"
        },
        "hostingPlanName": {
            "value": "joyplan"
        },
        "location": {
            "value": "Central US"
        },
        "serverFarmResourceGroup": {
            "value": "joywebapp"
        },
        "subscriptionId": {
            "value": "xxxxxxxxxxxxxxxxxxxx"
        }
    }
}
{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "name": {
            "value": "joytest11"
        },
        "storageName": {
            "value": "joystoragev1"
        },
        "location": {
            "value": "central us"
        },
        "subscriptionId": {
            "value": "b83c1ed3-xxxxxxxxxxx-2b83a074c23f"
        }
    }
}
更新

如果要创建具有消费计划的功能应用程序,可以参考下面的模板

样本:

{
    "$schema": "http://schema.management.azure.com/schemas/2014-04-01-preview/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "name": {
            "type": "String"
        },
        "storageName": {
            "type": "String"
        },
        "hostingPlanName": {
            "type": "String"
        },
        "location": {
            "type": "String"
        },
        "serverFarmResourceGroup": {
            "type": "String"
        },
        "subscriptionId": {
            "type": "String"
        }
    },
    "resources": [
        {
            "type": "Microsoft.Web/sites",
            "kind": "functionapp",
            "name": "[parameters('name')]",
            "apiVersion": "2016-03-01",
            "location": "[parameters('location')]",
            "properties": {
                "siteConfig": {
                    "appSettings": [
                        {
                            "name": "FUNCTIONS_WORKER_RUNTIME",
                            "value": "dotnet"
                        },
                        {
                            "name": "AzureWebJobsStorage",
                            "value": "[concat('DefaultEndpointsProtocol=https;AccountName=',parameters('storageName'),';AccountKey=',listKeys(resourceId('b83c1ed3-c5b6-44fb-b5ba-2b83a074c23f','joywebapp','Microsoft.Storage/storageAccounts', parameters('storageName')), '2015-05-01-preview').key1)]"
                        },
                        {
                            "name": "FUNCTIONS_EXTENSION_VERSION",
                            "value": "~2"
                        },
                        {
                            "name": "WEBSITE_NODE_DEFAULT_VERSION",
                            "value": "8.11.1"
                        },
                        {
                            "name": "APPINSIGHTS_INSTRUMENTATIONKEY",
                            "value": "[reference('microsoft.insights/components/joytestfuninsight', '2015-05-01').InstrumentationKey]"
                        }
                    ],
                    "alwaysOn": true
                },
                "name": "[parameters('name')]",
                "clientAffinityEnabled": false,
                "serverFarmId": "[concat('/subscriptions/', parameters('subscriptionId'),'/resourcegroups/', parameters('serverFarmResourceGroup'), '/providers/Microsoft.Web/serverfarms/', parameters('hostingPlanName'))]"
            },
            "dependsOn": [
                "microsoft.insights/components/joytestfuninsight"
            ]
        },
        {
            "type": "microsoft.insights/components",
            "name": "joytestfuninsight",
            "apiVersion": "2015-05-01",
            "location": "eastus",
            "properties": {
                "ApplicationId": "[parameters('name')]",
                "Request_Source": "IbizaWebAppExtensionCreate"
            }
        }
    ]
}
{
    "$schema": "http://schema.management.azure.com/schemas/2014-04-01-preview/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "name": {
            "type": "String"
        },
        "storageName": {
            "type": "String"
        },
        "location": {
            "type": "String"
        },
        "subscriptionId": {
            "type": "String"
        }
    },
    "resources": [
        {
            "type": "Microsoft.Web/sites",
            "kind": "functionapp",
            "name": "[parameters('name')]",
            "apiVersion": "2016-03-01",
            "location": "Central US",
            "properties": {
                "siteConfig": {
                    "appSettings": [
                        {
                            "name": "FUNCTIONS_WORKER_RUNTIME",
                            "value": "dotnet"
                        },
                        {
                            "name": "AzureWebJobsStorage",
                            "value": "[concat('DefaultEndpointsProtocol=https;AccountName=',parameters('storageName'),';AccountKey=',listKeys(resourceId('b83c1ed3-xxxxxxxxxxx-2b83a074c23f','joywebapp','Microsoft.Storage/storageAccounts', parameters('storageName')), '2015-05-01-preview').key1)]"
                        },
                        {
                            "name": "FUNCTIONS_EXTENSION_VERSION",
                            "value": "~2"
                        },
                        {
                            "name": "WEBSITE_CONTENTAZUREFILECONNECTIONSTRING",
                            "value": "[concat('DefaultEndpointsProtocol=https;AccountName=',parameters('storageName'),';AccountKey=',listKeys(resourceId('b83c1ed3-xxxxxxxxxxx-2b83a074c23f','joywebapp','Microsoft.Storage/storageAccounts', parameters('storageName')), '2015-05-01-preview').key1)]"
                        },
                        {
                            "name": "WEBSITE_CONTENTSHARE",
                            "value": "[concat(toLower(parameters('name')), 'b32d')]"
                        },
                        {
                            "name": "WEBSITE_NODE_DEFAULT_VERSION",
                            "value": "8.11.1"
                        },
                        {
                            "name": "APPINSIGHTS_INSTRUMENTATIONKEY",
                            "value": "[reference('microsoft.insights/components/joytest11insight', '2015-05-01').InstrumentationKey]"
                        }
                    ]
                },
                "name": "[parameters('name')]",
                "clientAffinityEnabled": false,
                "reserved": false
            },
            "dependsOn": [
                "microsoft.insights/components/joytest11insight"
            ]
        },
        {
            "type": "microsoft.insights/components",
            "name": "joytest11insight",
            "apiVersion": "2015-05-01",
            "location": "eastus",
            "properties": {
                "ApplicationId": "[parameters('name')]",
                "Request_Source": "IbizaWebAppExtensionCreate"
            }
        }
    ]
}
我的测试参数:

{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "name": {
            "value": "joytestfun"
        },
        "storageName": {
            "value": "joystoragev1"
        },
        "hostingPlanName": {
            "value": "joyplan"
        },
        "location": {
            "value": "Central US"
        },
        "serverFarmResourceGroup": {
            "value": "joywebapp"
        },
        "subscriptionId": {
            "value": "xxxxxxxxxxxxxxxxxxxx"
        }
    }
}
{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "name": {
            "value": "joytest11"
        },
        "storageName": {
            "value": "joystoragev1"
        },
        "location": {
            "value": "central us"
        },
        "subscriptionId": {
            "value": "b83c1ed3-xxxxxxxxxxx-2b83a074c23f"
        }
    }
}

我不确定那是不是真的。如果您在visual studio中创建azure函数并右键单击-->部署,它将创建该函数,而无需为ithm创建服务计划,奇怪的是,它显然不再创建消费应用程序服务计划。。。嗯,没关系,它不会马上出现,它就在那里。同样,根本不需要应用服务计划。我不知道为什么它只通过ARM模板强制执行,而不是在您从部署时强制执行vs@l----------------“功能必须有服务计划或消费计划,您可以在门户中检查您从vs创建的功能,它是否有消费计划?我想问题是,你如何让它进行消费plan@l--如果你想创建一个有消费计划的功能应用程序,你可以看到我的更新。