代码之家  ›  专栏  ›  技术社区  ›  Alex Gordon

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

  •  -1
  • Alex Gordon  · 技术社区  · 6 年前

    我想知道为什么 应用服务计划 创建了,而不仅仅是一个Azure函数和应用程序洞察:

    enter image description here

    在不强制创建应用程序服务计划的情况下,是否无法创建Azure函数应用程序?

    enter image description here

    在不创建应用服务计划组件的情况下,如何使用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": {}
    }
    
    2 回复  |  直到 6 年前
        1
  •  1
  •   Joy Wang    6 年前

    你可能会错过 serverFarmId 在模板中。尝试下面的模板,它不会创建单独的应用程序服务计划,在我的示例中,它将功能应用程序附加到现有的应用程序服务计划 joyplan 和存储帐户 joystoragev1 ,创建应用程序洞察力 joytestfuninsight 并与之相连。

    Sample:

    {
        "$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": "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"
            }
        }
    }
    

    更新 :

    如果你想创建一个带有消费计划的功能应用,你可以参考下面的模板。

    Sample:

    {
        "$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": "joytest11"
            },
            "storageName": {
                "value": "joystoragev1"
            },
            "location": {
                "value": "central us"
            },
            "subscriptionId": {
                "value": "b83c1ed3-xxxxxxxxxxx-2b83a074c23f"
            }
        }
    }
    
        2
  •  0
  •   4c74356b41    6 年前

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

    您可以将新的Azure函数附加到已经存在的应用程序服务计划中,这就是它。