【问题标题】:Azure Functions consumption plan namingAzure Functions 消费计划命名
【发布时间】:2019-03-21 10:31:04
【问题描述】:

我在 Azure 中创建了一个新的函数应用程序。我为应用服务计划选择了一个消费计划。

创建应用后,我的资源组中现在有了一个名为“WestEuropePlan”的新应用服务计划。

接下来的事情。 IT 部门表示“WestEuropePlan”不是应用服务计划的正确命名约定。

我有什么选择。创建 Function App 时,我不允许在使用基于消耗的计划时选择或命名现有计划。

我无法重命名自动生成的计划。

我无法在创建 Function App 之前手动创建基于消耗的计划。

我该怎么办?我唯一的选择是不使用基于消费的计划,而是创建一个我可以自己命名的普通应用服务计划吗?

我可以通过 azure CLI 或使用 ARM 模板做些什么吗?

【问题讨论】:

    标签: azure azure-functions azure-app-service-plans


    【解决方案1】:

    您可以使用 ARM 模板使用您选择的消费计划名称创建 Azure Function on Consumption 计划。下面是示例模板和参数文件:

    模板文件.json

    {
      "$schema": "https://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_RAGRS"],
          "metadata": {
            "description": "Storage Account type"
          }
        },
        "location": {
          "type": "string",
          "defaultValue": "[resourceGroup().location]",
          "metadata": {
            "description": "Location for all resources."
          }
        },
        "runtime": {
          "type": "string",
          "defaultValue": "node",
          "allowedValues": ["node", "dotnet", "java"],
          "metadata": {
            "description": "The language worker runtime to load in the function app."
          }
        }
      },
      "variables": {
        "functionAppName": "[parameters('appName')]",
        "hostingPlanName": "[parameters('appName')]",
        "applicationInsightsName": "[parameters('appName')]",
        "storageAccountName": "[concat(uniquestring(resourceGroup().id), 'azfunctions')]",
        "storageAccountid": "[concat(resourceGroup().id,'/providers/','Microsoft.Storage/storageAccounts/', variables('storageAccountName'))]",
        "functionWorkerRuntime": "[parameters('runtime')]"
      },
      "resources": [
        {
          "type": "Microsoft.Storage/storageAccounts",
          "name": "[variables('storageAccountName')]",
          "apiVersion": "2016-12-01",
          "location": "[parameters('location')]",
          "kind": "Storage",
          "sku": {
            "name": "[parameters('storageAccountType')]"
          }
        },
        {
          "type": "Microsoft.Web/serverfarms",
          "apiVersion": "2015-04-01",
          "name": "[variables('hostingPlanName')]",
          "location": "[parameters('location')]",
          "properties": {
            "name": "[variables('hostingPlanName')]",
            "computeMode": "Dynamic",
            "sku": "Dynamic"
          }
        },
        {
          "apiVersion": "2015-08-01",
          "type": "Microsoft.Web/sites",
          "name": "[variables('functionAppName')]",
          "location": "[parameters('location')]",
          "kind": "functionapp",
          "dependsOn": [
            "[resourceId('Microsoft.Web/serverfarms', variables('hostingPlanName'))]",
            "[resourceId('Microsoft.Storage/storageAccounts', variables('storageAccountName'))]"
          ],
          "properties": {
            "serverFarmId": "[resourceId('Microsoft.Web/serverfarms', variables('hostingPlanName'))]",
            "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": "~2"
                },
                {
                  "name": "WEBSITE_NODE_DEFAULT_VERSION",
                  "value": "8.11.1"
                },
                {
                  "name": "APPINSIGHTS_INSTRUMENTATIONKEY",
                  "value": "[reference(resourceId('microsoft.insights/components/', variables('applicationInsightsName')), '2015-05-01').InstrumentationKey]"
                },
                {
                  "name": "FUNCTIONS_WORKER_RUNTIME",
                  "value": "[variables('functionWorkerRuntime')]"
                }
              ]
            }
          }
        },
        {
          "apiVersion": "2018-05-01-preview",
          "name": "[variables('applicationInsightsName')]",
          "type": "microsoft.insights/components",
          "location": "East US",
          "tags": {
            "[concat('hidden-link:', resourceGroup().id, '/providers/Microsoft.Web/sites/', variables('applicationInsightsName'))]": "Resource"
          },
          "properties": {
            "ApplicationId": "[variables('applicationInsightsName')]",
            "Request_Source": "IbizaWebAppExtensionCreate"
          }
        }
      ]
    }
    

    参考:https://github.com/Azure/azure-quickstart-templates/tree/master/101-function-app-create-dynamic

    【讨论】:

      【解决方案2】:

      如果您正在使用 Azure CLI,以上答案将有所帮助,如果您想通过 Portal 本身进行操作,您可以执行以下操作,

      1. 在 Azure 功能 Review + create 步骤中,有一个选项可以下载自动化模板,您可以单击它。然后将显示模板以供下载。
      2. 现在点击部署
      3. 现在您可以轻松更改托管计划名称,同意条款和条件并点击购买。

      更多信息:http://jaliyaudagedara.blogspot.com/2020/08/azure-functions-consumption-plan-custom.html

      【讨论】:

      • 正是我想要的!对于那些好奇的人,您甚至不必编辑您遇到的任何 JSON。如果您阅读这篇文章,您会看到门户网站也会为每个变量输入生成一个充满文本框的屏幕。很方便。
      【解决方案3】:

      您可以从此 ARM 模板创建。没有应用洞察,它会询问 appName、hostingPlanName、storageAccountName、storageAccountType、位置和运行时

      {
      "$schema": "https://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."
              }
          },
           "hostingPlanName": {
              "type": "string",
              "metadata": {
                  "description": "The name of the consumption plan that you wish to create."
              }
          },
          "storageAccountName": {
              "type": "string",
              "metadata": {
                  "description": "The name of the storage account name that you wish to create."
              }
          },
          "storageAccountType": {
              "type": "string",
              "defaultValue": "Standard_LRS",
              "allowedValues": [
                  "Standard_LRS",
                  "Standard_GRS",
                  "Standard_RAGRS"
              ],
              "metadata": {
                  "description": "Storage Account type"
              }
          },
          "location": {
              "type": "string",
              "defaultValue": "[resourceGroup().location]",
              "metadata": {
                  "description": "Location for all resources."
              }
          },
          "runtime": {
              "type": "string",
              "defaultValue": "node",
              "allowedValues": [
                  "node",
                  "dotnet",
                  "java"
              ],
              "metadata": {
                  "description": "The language worker runtime to load in the function app."
              }
          }
      },
      "variables": {
          "functionAppName": "[parameters('appName')]",
          "hostingPlanName": "[parameters('hostingPlanName')]",
          "storageAccountName": "[parameters('storageAccountName')]",
          "storageAccountid": "[concat(resourceGroup().id,'/providers/','Microsoft.Storage/storageAccounts/', variables('storageAccountName'))]",
          "functionWorkerRuntime": "[parameters('runtime')]"
      },
      "resources": [
          {
              "type": "Microsoft.Storage/storageAccounts",
              "name": "[variables('storageAccountName')]",
              "apiVersion": "2016-12-01",
              "location": "[parameters('location')]",
              "kind": "Storage",
              "sku": {
                  "name": "[parameters('storageAccountType')]"
              }
          },
          {
              "type": "Microsoft.Web/serverfarms",
              "apiVersion": "2018-02-01",
              "name": "[variables('hostingPlanName')]",
              "location": "[parameters('location')]",
              "sku": {
                  "name": "Y1",
                  "tier": "Dynamic"
              },
              "properties": {
                  "name": "[variables('hostingPlanName')]",
                  "computeMode": "Dynamic"
              }
          },
          {
              "apiVersion": "2015-08-01",
              "type": "Microsoft.Web/sites",
              "name": "[variables('functionAppName')]",
              "location": "[parameters('location')]",
              "kind": "functionapp",
              "dependsOn": [
                  "[resourceId('Microsoft.Web/serverfarms', variables('hostingPlanName'))]",
                  "[resourceId('Microsoft.Storage/storageAccounts', variables('storageAccountName'))]"
              ],
              "properties": {
                  "serverFarmId": "[resourceId('Microsoft.Web/serverfarms', variables('hostingPlanName'))]",
                  "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": "~2"
                          },
                          {
                              "name": "WEBSITE_NODE_DEFAULT_VERSION",
                              "value": "8.11.1"
                          },
                          {
                              "name": "FUNCTIONS_WORKER_RUNTIME",
                              "value": "[variables('functionWorkerRuntime')]"
                          }
                      ]
                  }
              }
          }
      ]
      

      }

      【讨论】:

        【解决方案4】:

        我建议你使用 Az PowerShell 或 AzureCLI 来命名你的 Function App Consumption Plan,它比 ARM Template 更容易维护。

        诀窍是您需要先创建一个 B1 计划(因此使用您的自定义名称),然后更改 FunctionApp 上的一些设置以适应 ConsumptionPlan 限制(即:AlwaysOn=$false),然后您可以更新/更改您的应用服务计划 B1 到消费计划(称为 Y1)

        请在 PowerShell 中找到我的脚本来创建 Linux 消费计划: (对于 Windows 计划,您可以删除变量 $fullObject 中的“kind”和“properties.reserved=true”,将变量 $os_type 上的“linux”替换为“windows”并删除 $my_runtimeVersion 变量并将 $my_runtime 变量从“ python" 到 "dotnet" (或将其删除,默认为 dotnet))

        # Function App configuration object - Need to be a Basic Tier first as you cannot directly create a consumption plan
        $fullObject = @{
           location = "West Europe"
           sku = @{
                name = "B1"
                tier = "Basic"
           }
           kind = "linux"
           properties = @{
                reserved = $true
           }
        }
        
        $resourceGroupName = "rg-my-test"
        $serverFarmName = "aspl-my-test"
        $storageName = "stg-my-test"
        $functionAppName = "fa-my-test"
        $my_runtime = "python"
        $my_runtimeVersion = "3.8"
        $os_type = "linux"
        
        Write-Host "Step 1: CREATING APP SERVICE PLAN B1:Basic named [$serverFarmName]"
        # Create a server farm which will host the function app in the resource group specified
        New-AzResource -ResourceGroupName $resourceGroupName -ResourceType "Microsoft.Web/serverfarms" -Name $serverFarmName -IsFullObject -PropertyObject $fullObject -Force
        Write-Host "Step 1: Done"
        
        Write-Host "Step 2: CREATING STORAGE ACCOUNT named [$storageName]"
        # Create a storage account which will contain the Azure Function script
        New-AzStorageAccount -ResourceGroupName $resourceGroupName -AccountName $storageName -Location westeurope -SkuName Standard_LRS
        Write-Host "Step 2: Done"
        
        Write-Host "Step 3: CREATING FUNCTION APP named [$functionAppName]"
        # Create a function app in the server farm previously created
        New-AzFunctionApp -ResourceGroupName $resourceGroupName -Name $functionAppName -PlanName $serverFarmName -StorageAccount $storageName -Runtime $my_runtime -FunctionsVersion 3 -OSType $os_type -RuntimeVersion $my_runtimeVersion -DisableApplicationInsights
        Write-Host "Step 3: Done"
        
        Write-Host "Step 4a: GET FUNCTION APP as an PSObject"
        $funcApp = Get-AzResource -ResourceType 'microsoft.web/sites' -ResourceGroupName $resourceGroupName -ResourceName $functionAppName
        Write-Host "Step 4a: Done"
        
        Write-Host "Step 4b: SET FUNCTION APP settings"
        Write-Host "  siteConfig:"
        Write-Host "    AlwaysOn: false"
        Write-Host "    FtpsState: Disabled"
        Write-Host "    MinTlsVersion: 1.2"
        Write-Host "    Http20Enabled: true"
        Write-Host "  HttpsOnly: true"
        $fullObject = @{
           siteConfig = @{
              AlwaysOn = $false
              FtpsState = "Disabled"
              MinTlsVersion = "1.2"
              Http20Enabled = $true
           }
           HttpsOnly = $true
        }
        
        $funcApp | Set-AzResource -PropertyObject $fullObject -Force
        Write-Host "Step 4b: Done"
        
        Write-Host "Step 5: Set App Service Plan to Dynamic Consumption Plan"
        Set-AzAppServicePlan -Name $serverFarmName -ResourceGroupName $resourceGroupName -Tier Y1
        Write-Host "Step 5: Done"
        

        在 Azure CLI 中,将计划切换到消耗计划的命令是:

        az appservice plan update --name aspl-my-test --resource-group rg-my-test --set sku.name=Y1
        

        【讨论】:

          猜你喜欢
          • 2018-09-28
          • 1970-01-01
          • 2020-05-30
          • 2019-12-08
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多