未使用ARM模板在Azure函数应用程序内创建函数

a2mppw5e  于 2023-08-07  发布在  其他
关注(0)|答案(1)|浏览(95)

我正在尝试使用ARM模板将Azure Function应用程序部署在这个函数中,并使用Azure Blob触发器。
我能够部署函数应用程序,它已经启动并运行,但里面的函数没有被创建。
首先,我创建了一个函数应用程序,并在其中创建一个函数。我将该函数的所有文件复制到blob存储中,并在appsetting中提供 init*.pyfunction.json**文件

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "metadata": {
    "_generator": {
      "name": "bicep",
      "version": "0.10.61.36676",
      "templateHash": "2440974564149075183"
    }
  },
  "parameters": {
    "functionAppName": {
      "type": "string",
      "defaultValue": "test-function-name",
      "metadata": {
        "description": "The name of the Azure Function app."
      }
    },
    "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."
      }
    },
    "appInsightsLocation": {
      "type": "string",
      "defaultValue": "[resourceGroup().location]",
      "metadata": {
        "description": "Location for Application Insights"
      }
    },
    "functionWorkerRuntime": {
      "type": "string",
      "defaultValue": "python",
      "allowedValues": [
        "dotnet",
        "node",
        "python",
        "java"
      ],
      "metadata": {
        "description": "The language worker runtime to load in the function app."
      }
    },
    "linuxFxVersion": {
      "type": "string",
      "defaultValue": "python|3.9",
      "metadata": {
        "description": "Required for Linux app to represent runtime stack in the format of 'runtime|runtimeVersion'. For example: 'python|3.9'"
      }
    }
  },
  "variables": {
    "hostingPlanName": "[parameters('functionAppName')]",
    "applicationInsightsName": "[parameters('functionAppName')]",
    "storageAccountName": "[format('{0}azfunctions', uniqueString(resourceGroup().id))]"
  },
  "resources": [
    {
      "type": "Microsoft.Storage/storageAccounts",
      "apiVersion": "2022-05-01",
      "name": "[variables('storageAccountName')]",
      "location": "[parameters('location')]",
      "sku": {
        "name": "[parameters('storageAccountType')]"
      },
      "kind": "Storage"
    },
    {
      "type": "Microsoft.Web/serverfarms",
      "apiVersion": "2021-02-01",
      "name": "[variables('hostingPlanName')]",
      "location": "[parameters('location')]",
      "sku": {
        "name": "Y1",
        "tier": "Dynamic",
        "size": "Y1",
        "family": "Y"
      },
      "properties": {
        "computeMode": "Dynamic",
        "reserved": true
      }
    },
    {
      "type": "Microsoft.Insights/components",
      "apiVersion": "2020-02-02",
      "name": "[variables('applicationInsightsName')]",
      "location": "[parameters('appInsightsLocation')]",
      "tags": {
        "[format('hidden-link:{0}', resourceId('Microsoft.Web/sites', variables('applicationInsightsName')))]": "Resource"
      },
      "properties": {
        "Application_Type": "web"
      },
      "kind": "web"
    },
    {
      "type": "Microsoft.Web/sites",
      "apiVersion": "2022-03-01",
      "name": "[parameters('functionAppName')]",
      "location": "[parameters('location')]",
      "kind": "functionapp,linux",
      "properties": {
        "reserved": true,
        "serverFarmId": "[resourceId('Microsoft.Web/serverfarms', variables('hostingPlanName'))]",
        "siteConfig": {
          "linuxFxVersion": "[parameters('linuxFxVersion')]",
          "appSettings": [
            {
              "name": "APPINSIGHTS_INSTRUMENTATIONKEY",
              "value": "[reference(resourceId('Microsoft.Insights/components', parameters('functionAppName')), '2015-05-01').InstrumentationKey]"
            },
            {
              "name": "AzureWebJobsStorage",
              "value": "[format('DefaultEndpointsProtocol=https;AccountName={0};EndpointSuffix={1};AccountKey={2}', variables('storageAccountName'), environment().suffixes.storage, listKeys(resourceId('Microsoft.Storage/storageAccounts', variables('storageAccountName')), '2019-06-01').keys[0].value)]"
            },
            {
              "name": "WEBSITE_CONTENTAZUREFILECONNECTIONSTRING",
              "value": "[format('DefaultEndpointsProtocol=https;AccountName={0};EndpointSuffix={1};AccountKey={2}', variables('storageAccountName'), environment().suffixes.storage, listKeys(resourceId('Microsoft.Storage/storageAccounts', variables('storageAccountName')), '2019-06-01').keys[0].value)]"
            },
            {
              "name": "WEBSITE_CONTENTSHARE",
              "value": "[toLower(parameters('functionAppName'))]"
            },
            {
              "name": "FUNCTIONS_EXTENSION_VERSION",
              "value": "~4"
            },
            {
              "name": "FUNCTIONS_WORKER_RUNTIME",
              "value": "[parameters('functionWorkerRuntime')]"
            },
            {
              "name": "SCM_DO_BUILD_DURING_DEPLOYMENT",
              "value": "true"
            }
          ]
        },
        "apiDefinition": 
        {
            "value": [
            {
              "name": "test-trigger-function",
              "type": "function",
              "properties": {
                  "script_href": "blob_url/folder/__init__.py",
                  "script_root_path_href": "blob_url/folder/",
                  "config_href": "blob_url/folder/function.json",
                  "config": {},
                  "language": "python",
                  "isDisabled": false
              }
            }
          ]
        }
      },
      "dependsOn": [
        "[resourceId('Microsoft.Web/serverfarms', variables('hostingPlanName'))]",
        "[resourceId('Microsoft.Insights/components', variables('applicationInsightsName'))]",
        "[resourceId('Microsoft.Storage/storageAccounts', variables('storageAccountName'))]"
      ]
    }
  ]
}

字符串
我想创建一个函数应用程序,其操作系统为Linux,运行时为Python3.9,并且在该函数中可以从blob存储中获取旧的函数配置和文件。
我可以创建下面所示的功能应用程序。

的数据

现在我想在下面的函数应用程序中创建函数。

我试着遵循文档,但我无法弄清楚如何在函数应用程序中创建函数。

pdtvr36n

pdtvr36n1#

未使用ARM模板在Azure函数App中创建函数:-
在解决您的需求之后,我发现了一种方法,可以在函数App中添加一个函数,使用"Microsoft.Web/sites/functions"资源类型,如下所示。

  • ARM(Json)格式代码:*
{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "metadata": {
    "_generator": {
      "name": "bicep",
      "version": "0.19.5.34762",
      "templateHash": "1037450281519309886"
    }
  },
  "parameters": {
    "functionAppName": {
      "type": "string",
      "defaultValue": "newxxx",
      "metadata": {
        "description": "The name of the Azure Function app."
      }
    },
    "storageAccountName": {
      "type": "string",
      "metadata": {
        "description": "The name of the storage account that you wish to use."
      }
    },
    "storageAccountType": {
      "type": "string",
      "defaultValue": "Standard_LRS",
      "allowedValues": [
        "Standard_LRS",
        "Standard_GRS",
        "Standard_RAGRS"
      ],
      "metadata": {
        "description": "Storage Account type"
      }
    },
    "blobContainerName": {
      "type": "string",
      "metadata": {
        "description": "The name of the blob container that you wish to use."
      }
    },
    "location": {
      "type": "string",
      "defaultValue": "[resourceGroup().location]",
      "metadata": {
        "description": "Location for all resources."
      }
    },
    "appInsightsLocation": {
      "type": "string",
      "defaultValue": "[resourceGroup().location]",
      "metadata": {
        "description": "Location for Application Insights"
      }
    },
    "functionWorkerRuntime": {
      "type": "string",
      "defaultValue": "python",
      "allowedValues": [
        "dotnet",
        "node",
        "python",
        "java"
      ],
      "metadata": {
        "description": "The language worker runtime to load in the function app."
      }
    },
    "functionName": {
      "type": "string",
      "metadata": {
        "description": "The name of the function that you wish to create."
      }
    },
    "linuxFxVersion": {
      "type": "string",
      "defaultValue": "python|3.9",
      "metadata": {
        "description": "Required for Linux app to represent runtime stack in the format of 'runtime|runtimeVersion'. For example: 'python|3.9'"
      }
    }
  },
  "variables": {
    "hostingPlanName": "[parameters('functionAppName')]",
    "applicationInsightsName": "[parameters('functionAppName')]",
    "storageAccountName_var": "[format('{0}azfunctions', uniqueString(resourceGroup().id))]"
  },
  "resources": [
    {
      "type": "Microsoft.Storage/storageAccounts",
      "apiVersion": "2022-05-01",
      "name": "'storage${uniqueString(resourceGroup().id)}'",
      "location": "[parameters('location')]",
      "sku": {
        "name": "[parameters('storageAccountType')]"
      },
      "kind": "Storage"
    },
    {
      "type": "Microsoft.Web/serverfarms",
      "apiVersion": "2021-02-01",
      "name": "[variables('hostingPlanName')]",
      "location": "[parameters('location')]",
      "sku": {
        "name": "Y1",
        "tier": "Dynamic",
        "size": "Y1",
        "family": "Y"
      },
      "properties": {
        "computeMode": "Dynamic",
        "reserved": true
      }
    },
    {
      "type": "Microsoft.Insights/components",
      "apiVersion": "2020-02-02",
      "name": "[variables('applicationInsightsName')]",
      "location": "[parameters('appInsightsLocation')]",
      "tags": {
        "[format('hidden-link:{0}', resourceId('Microsoft.Web/sites', variables('applicationInsightsName')))]": "Resource"
      },
      "properties": {
        "Application_Type": "web"
      },
      "kind": "web"
    },
    {
      "type": "Microsoft.Web/sites",
      "apiVersion": "2022-03-01",
      "name": "[parameters('functionAppName')]",
      "location": "[parameters('location')]",
      "kind": "functionapp,linux",
      "properties": {
        "reserved": true,
        "serverFarmId": "[resourceId('Microsoft.Web/serverfarms', variables('hostingPlanName'))]",
        "siteConfig": {
          "linuxFxVersion": "[parameters('linuxFxVersion')]",
          "appSettings": [
            {
              "name": "APPINSIGHTS_INSTRUMENTATIONKEY",
              "value": "[reference(resourceId('Microsoft.Insights/components', parameters('functionAppName')), '2015-05-01').InstrumentationKey]"
            },
            {
              "name": "AzureWebJobsStorage",
              "value": "[format('DefaultEndpointsProtocol=https;AccountName={0};EndpointSuffix={1};AccountKey={2}', variables('storageAccountName_var'), environment().suffixes.storage, listKeys(resourceId('Microsoft.Storage/storageAccounts', variables('storageAccountName_var')), '2019-06-01').keys[0].value)]"
            },
            {
              "name": "WEBSITE_CONTENTAZUREFILECONNECTIONSTRING",
              "value": "[format('DefaultEndpointsProtocol=https;AccountName={0};EndpointSuffix={1};AccountKey={2}', variables('storageAccountName_var'), environment().suffixes.storage, listKeys(resourceId('Microsoft.Storage/storageAccounts', variables('storageAccountName_var')), '2019-06-01').keys[0].value)]"
            },
            {
              "name": "WEBSITE_CONTENTSHARE",
              "value": "[toLower(parameters('functionAppName'))]"
            },
            {
              "name": "FUNCTIONS_EXTENSION_VERSION",
              "value": "~4"
            },
            {
              "name": "FUNCTIONS_WORKER_RUNTIME",
              "value": "[parameters('functionWorkerRuntime')]"
            },
            {
              "name": "SCM_DO_BUILD_DURING_DEPLOYMENT",
              "value": "true"
            }
          ]
        }
      },
      "dependsOn": [
        "[resourceId('Microsoft.Web/serverfarms', variables('hostingPlanName'))]"
      ]
    },
    {
      "type": "Microsoft.Storage/storageAccounts",
      "apiVersion": "2021-08-01",
      "name": "[parameters('storageAccountName')]",
      "location": "[parameters('location')]",
      "tags": "sds",
      "sku": {
        "name": "Premium_LRS"
      },
      "kind": "[parameters('storageAccountType')]"
    },
    {
      "type": "Microsoft.Storage/storageAccounts/blobServices",
      "apiVersion": "2021-06-01",
      "name": "[format('{0}/{1}', parameters('storageAccountName'), 'default')]",
      "dependsOn": [
        "[resourceId('Microsoft.Storage/storageAccounts', parameters('storageAccountName'))]"
      ]
    },
    {
      "type": "Microsoft.Storage/storageAccounts/blobServices/containers",
      "apiVersion": "2019-06-01",
      "name": "[format('{0}/{1}/{2}', parameters('storageAccountName'), 'default', format('{0}default{1}', parameters('storageAccountName'), parameters('blobContainerName')))]",
      "properties": {
        "publicAccess": "None"
      },
      "dependsOn": [
        "[resourceId('Microsoft.Storage/storageAccounts/blobServices', parameters('storageAccountName'), 'default')]"
      ]
    },
    {
      "type": "Microsoft.Web/sites/functions",
      "apiVersion": "2018-02-01",
      "name": "[format('{0}/{1}', parameters('functionAppName'), format('{0}', parameters('functionName')))]",
      "properties": {
        "config": {
          "bindings": [
            {
              "name": "myBlob",
              "type": "blobTrigger",
              "direction": "in",
              "path": "[format('default/{0}/{{name}}', parameters('blobContainerName'))]",
              "connection": "AzureWebJobsStorage"
            }
          ],
          "disabled": false
        }
      },
      "dependsOn": [
        "[resourceId('Microsoft.Web/sites', parameters('functionAppName'))]",
        "[resourceId('Microsoft.Storage/storageAccounts/blobServices/containers', parameters('storageAccountName'), 'default', format('{0}default{1}', parameters('storageAccountName'), parameters('blobContainerName')))]"
      ]
    }
  ]
}

字符串

  • 二头肌文件格式代码:*
@description('The name of the Azure Function app.')
param  functionAppName  string = 'newjappsun'
@description('The name of the storage account that you wish to use.')
param  storageAccountName  string = 'latestjstore'
@description('Storage Account type')
@allowed([
'Standard_LRS'
'Standard_GRS'
'Standard_RAGRS'
])
param  storageAccountType  string = 'Standard_LRS'
@description('The name of the blob container that you wish to use.')
param  blobContainerName  string = 'new'
@description('Location for all resources.')
param  location  string = resourceGroup().location
@description('Location for Application Insights')
param  appInsightsLocation  string = resourceGroup().location
@description('The language worker runtime to load in the function app.')
@allowed([
'dotnet'
'node'
'python'
'java'
])
param  functionWorkerRuntime  string = 'python'
@description('The name of the function that you wish to create.')
param  functionName  string = 'newfuncj'
@description('Required for Linux app to represent runtime stack in the format of \'runtime|runtimeVersion\'. For example: \'python|3.9\'')
param  linuxFxVersion  string = 'python|3.9'
var  hostingPlanName = functionAppName
var  applicationInsightsName = functionAppName
resource  hostingPlan  'Microsoft.Web/serverfarms@2021-02-01' = {
name: hostingPlanName
location: location
sku: {
name: 'Y1'
tier: 'Dynamic'
size: 'Y1'
family: 'Y'
}
properties: {
computeMode: 'Dynamic'
reserved: true
}
}
resource  applicationInsights  'Microsoft.Insights/components@2020-02-02' = {
name: applicationInsightsName
location: appInsightsLocation
tags: {
'hidden-link:${resourceId('Microsoft.Web/sites',  applicationInsightsName)}': 'Resource'
}
properties: {
Application_Type: 'web'
}
kind: 'web'
}
resource  functionApp 'Microsoft.Web/sites@2022-03-01' = {
name: functionAppName
location: location
kind: 'functionapp,linux'
properties: {
reserved: true
serverFarmId: hostingPlan.id
siteConfig: {
linuxFxVersion: linuxFxVersion
appSettings: [
{
name: 'APPINSIGHTS_INSTRUMENTATIONKEY'
value: reference(resourceId('Microsoft.Insights/components',  functionAppName),  '2015-05-01').InstrumentationKey
}
{
name: 'AzureWebJobsStorage'
value: 'DefaultEndpointsProtocol=https;AccountName=${storageAccountName};EndpointSuffix=${environment().suffixes.storage};AccountKey=${listKeys(resourceId('Microsoft.Storage/storageAccounts',  storageAccountName),  '2019-06-01').keys[0].value}'
}
{
name: 'WEBSITE_CONTENTAZUREFILECONNECTIONSTRING'
value: 'DefaultEndpointsProtocol=https;AccountName=${storageAccountName};EndpointSuffix=${environment().suffixes.storage};AccountKey=${listKeys(resourceId('Microsoft.Storage/storageAccounts',  storageAccountName),  '2019-06-01').keys[0].value}'
}
{
name: 'WEBSITE_CONTENTSHARE'
value: toLower(functionAppName)
}
{
name: 'FUNCTIONS_EXTENSION_VERSION'
value: '~4'
}
{
name: 'FUNCTIONS_WORKER_RUNTIME'
value: functionWorkerRuntime
}
{
name: 'SCM_DO_BUILD_DURING_DEPLOYMENT'
value: 'true'
}
]
}
}
}
resource  storageAccount 'Microsoft.Storage/storageAccounts@2021-08-01' = {
name: storageAccountName
location: location
sku: {
name: 'Standard_LRS'
}
kind: 'StorageV2'
}
resource  blobService 'Microsoft.Storage/storageAccounts/blobServices@2021-06-01' = {
name: 'default'
parent: storageAccount
}
resource  storageAccountName_default_blobContainer  'Microsoft.Storage/storageAccounts/blobServices/containers@2019-06-01' = {
name: '${storageAccountName}default${blobContainerName}'
parent: blobService
properties: {
publicAccess: 'None'
}
}
resource  functionAppName_function 'Microsoft.Web/sites/functions@2018-02-01' = {
parent: functionApp
name: '${functionName}'
properties: {
config: {
bindings: [
{
name: 'myBlob'
type: 'blobTrigger'
direction: 'in'
path: 'default/${blobContainerName}/{name}'
connection: 'AzureWebJobsStorage'
}
]
disabled: false
}
}
dependsOn: [
storageAccountName_default_blobContainer
]
}

  • 输出:*

x1c 0d1x的数据




请参考@GyanBlog的文章以了解模板的更详细结构。

相关问题