Azure Functions消费计划命名

时间:2019-03-21 10:31:04

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

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

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

下一件事。 IT部门说“ WestEuropePlan”不是App Service计划的正确命名约定。

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

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

在创建功能应用之前,我无法手动创建基于消费的计划。

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

我可以从Azure的CLI或使用ARM模板做些什么吗?

4 个答案:

答案 0 :(得分:5)

您可以使用ARM模板为消费计划选择名称,从而创建一个Azure消费计划功能。下面是示例模板和参数文件:

Templatefile.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

答案 1 :(得分:1)

您可以从此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')]"
                    }
                ]
            }
        }
    }
]

}

答案 2 :(得分:1)

如果您使用的是Azure CLI,以上答案将有所帮助;如果要通过Portal本身进行操作,则可以执行以下操作,

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

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

答案 3 :(得分:0)

建议您使用 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