Barebones Python函数应用程序通过IAC forAzure

问题描述 投票:0回答:1
我需要一个裸露的最小二头肌文件来通过基础架构作为代码(IAC)在Azure中创建一个thement python 3.11函数应用程序。我不希望应用程序见解支持。我应该能够通过以下一行命令部署到名为rg-py-func-tst的先前存在资源组:

az deployment group create --resource-group rg-py-func-tst --template-file main.bicep

我看过git上的样本,尝试将模板直接从Azure导出,甚至短暂地尝试使用Azure Resource Manager(ARM)模板。通过所有这些,这个二头肌对我来说似乎最合理:
// Created by Microsoft Copilot and Google Gemini
// This Bicep script deploys an EMPTY Python 3.11 Function App named
// 'shawnopyFuncTest' without App Insights, at service level Y1. 
// It creates a storage account named 'pyfunctest100', an app service
// plan named 'pyfunctestAppService', and the function app itself.
//
// I do not have the Python code yet. The Python code will be
// deployed in a separate project. I just want to create an 
// empty Python Function App

@description('Name of the storage account')
param storageAccountName string = 'pyfunctest100'

@description('Name of the app service plan')
param appServicePlanName string = 'pyfunctestAppService'

@description('Name of the function app')
param functionAppName string = 'shawnopyFuncTest'

@description('Location for all resources')
param location string = resourceGroup().location

// Define the storage account resource
resource storageAccount 'Microsoft.Storage/storageAccounts@2022-09-01' = {
  name: storageAccountName
  location: location
  sku: {
    name: 'Standard_LRS'
  }
  kind: 'StorageV2'
}

// Define the app service plan resource
resource appServicePlan 'Microsoft.Web/serverfarms@2022-03-01' = {
  name: appServicePlanName
  location: location
  kind: 'linux'
  sku: {
    name: 'Y1'
    tier: 'Dynamic'
  }
  properties:{
    reserved: true
  }
}

// Define the function app resource (Updated API version)
resource functionApp 'Microsoft.Web/sites@2022-09-01' = {
  name: functionAppName
  location: location
  kind: 'functionapp,linux'
  properties: {
    serverFarmId: appServicePlan.id
    siteConfig: {
      linuxFxVersion: 'Python|3.11'
      appSettings: [
        {
          name: 'FUNCTIONS_WORKER_RUNTIME'
          value: 'python'
        }
        {
          name: 'AzureWebJobsStorage'
          value: storageAccount.properties.primaryEndpoints.blob
        }
      ]
    }
  }
}

output storageAccountName string = storageAccount.name
output appServicePlanName string = appServicePlan.name
output functionAppName string = functionApp.name

我已经在两个完全独立的Azure租户中运行了上述部署,结果始终是相同的。我的资源组RG-PY-FUNC-TST填充了:一个名为Pyfunctest100的存储帐户;一个名为PyfunctappService的应用程序服务计划;并且,一个名为ShawnopyFunctest的功能应用程序。那就是我想要的;不幸的是,这不是故事的结尾。

当我打开新部署的空功能应用程序shawnopyfunctest时,我在运行时版本字段中看到文本“错误”:

但我希望为一个空的python函数应用程序看到的是: Azure Portal Function App Page showing Runtime Version of Error

有人可以帮助我纠正Copilot女士和双子座创建的二头肌吗?如果没有,您能否提供一个更简单,更干净的模板,仍然可以执行我的需求? Azure Portal Function App Page for a Fresh Empty Python Function App Runtime Version is 4.1036.2.2 aCorcording to thedocs

您可以通过通过

FUNCTIONS_EXTENSION_VERSION

传递
python azure-functions azure-bicep infrastructure-as-code
1个回答
0
投票
值来定位特定的运行时版本。请参阅下面的修改示例。



// Created by Microsoft Copilot and Google Gemini
// This Bicep script deploys an EMPTY Python 3.11 Function App named
// 'shawnopyFuncTest' without App Insights, at service level Y1. 
// It creates a storage account named 'pyfunctest100', an app service
// plan named 'pyfunctestAppService', and the function app itself.
//
// I do not have the Python code yet. The Python code will be
// deployed in a separate project. I just want to create an 
// empty Python Function App

@description('Name of the storage account')
param storageAccountName string = 'pyfunctest100'

@description('Name of the app service plan')
param appServicePlanName string = 'pyfunctestAppService'

@description('Name of the function app')
param functionAppName string = 'shawnopyFuncTest'

@description('Location for all resources')
param location string = resourceGroup().location

// Define the storage account resource
resource storageAccount 'Microsoft.Storage/storageAccounts@2022-09-01' = {
  name: storageAccountName
  location: location
  sku: {
    name: 'Standard_LRS'
  }
  kind: 'StorageV2'
}

// Define the app service plan resource
resource appServicePlan 'Microsoft.Web/serverfarms@2022-03-01' = {
  name: appServicePlanName
  location: location
  kind: 'linux'
  sku: {
    name: 'Y1'
    tier: 'Dynamic'
  }
  properties:{
    reserved: true
  }
}

// Define the function app resource (Updated API version)
resource functionApp 'Microsoft.Web/sites@2022-09-01' = {
  name: functionAppName
  location: location
  kind: 'functionapp,linux'
  properties: {
    serverFarmId: appServicePlan.id
    siteConfig: {
      linuxFxVersion: 'Python|3.11'
      appSettings: [
        {
          name: 'FUNCTIONS_WORKER_RUNTIME'
          value: 'python'
        }
        {
          name: 'AzureWebJobsStorage'
          value: storageAccount.properties.primaryEndpoints.blob
        }
        {
          name: 'FUNCTIONS_EXTENSION_VERSION'
          value: '~4'
        }
      ]
    }
  }
}

output storageAccountName string = storageAccount.name
output appServicePlanName string = appServicePlan.name
output functionAppName string = functionApp.name


	

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.