我想了解为什么要创建整个 app服务计划,而不仅仅是创建一个Azure函数和应用见解:
是否可以在不强制创建应用程序服务计划的情况下创建Azure Function应用程序?
如何使用ARM模板创建Azure功能,而不创建App Service Plan组件?
这是我的完整模板:
{
"$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": {}
}
答案 0 :(得分:1)
您可能会错过模板中的serverFarmId
。请尝试以下模板,它不会创建单独的应用程序服务计划,在我的示例中,它将功能应用程序附加到现有应用程序服务计划joyplan
和存储帐户joystoragev1
上,创建应用程序见解{{1 }}并附加到它。
示例:
joytestfuninsight
我的测试参数:
{
"$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"
}
}
]
}
更新:
如果要使用消费计划创建Function App,可以参考下面的模板。
示例:
{
"$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": "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"
}
}
]
}
答案 1 :(得分:0)
Azure Function需要应用程序服务计划才能运行,因此如果没有Azure Service,您将无法真正创建Azure Function。
您可以将新的Azure Function附加到已经存在的App Service计划中。