我正在从 ARM 模板迁移到 Bicep 文件。 我正在使用 VS Code 扩展将 ARM 反编译为 Bicep。
我发现 FunctionApp 和 AppService 之间在处理 appSettings 方面存在差异。我想知道这些之间是否有什么区别以及是否首选其中一个。
resource funcApp 'Microsoft.Web/sites@2023-12-01' = {
name: funcAppName
location: location
kind: 'functionapp'
resource funcApp_appSettings 'Microsoft.Web/sites/config@2023-12-01' = {
parent: funcApp
name: 'appsettings'
properties: {
KEY1: value1
KEY2: value2
}
}
resource appService 'Microsoft.Web/sites@2023-12-01' = {
name: appService_name
location: location
properties: {
enabled: true
serverFarmId: appServicePlan_id
siteConfig: {
appSettings: [
{
name: KEY1
value: value1
}
{
name: KEY2
value: value2
}
]
}
}
}
我发现 FunctionApp 和 AppService 之间在处理 appSettings 方面存在差异。我想知道这些之间是否有什么区别以及是否首选其中一个。
是的,对于 Azure 应用服务的应用设置配置,这两种方法都是有效的。每个人的架构实现方式都不同,您需要根据需求在这些架构之间进行选择。
主要区别:
对于应用程序服务,我们通常在网站资源提供程序中的
site config{}
块下定义应用程序设置。但对于函数应用程序,我们使用一个单独的资源提供程序,称为
Web/sites/config
配置应用程序设置。这也不是强制性的。还可以在函数应用程序下使用 site_config
块来实现更简单的配置。
基本上,函数应用程序的应用程序设置功能使我们能够独立于主函数应用程序资源来管理设置。 (配置为子资源)
但在应用程序服务中,所有设置配置都将绑定在网络应用程序中,因为它的配置设置经常更新。
注意:如果您有庞大的设置或需要任何模块化功能,则 Function App 方法会更有用。对于更简单的配置而不是复杂的配置,应用服务方法是最佳选择。这意味着,如果不需要频繁更改配置,则内联
siteConfig.appSettings
将是合适的。
示例:
我已经为 Function App 和 App 服务 执行了示例二头肌脚本,如下所示,带有详细的门户视图。
param storageType string = 'Standard_LRS'
param location string = 'WestUS2'
param runtime string = 'node'
resource storageAccount 'Microsoft.Storage/storageAccounts@2022-05-01' = {
name: 'xxxx'
location: location
sku: {
name: storageType
}
kind: 'Storage'
properties: {
supportsHttpsTrafficOnly: true
defaultToOAuthAuthentication: true
}
}
resource hostingPlan 'Microsoft.Web/serverfarms@2021-03-01' = {
name: 'xxx'
location: location
sku: {
name: 'Y1'
tier: 'Dynamic'
}
properties: {}
}
resource functionApp 'Microsoft.Web/sites@2021-03-01' = {
name: 'xxxx'
location: location
kind: 'functionapp'
identity: {
type: 'SystemAssigned'
}
properties: {
serverFarmId: hostingPlan.id
siteConfig: {
appSettings: [
{
name: 'FUNCTIONS_EXTENSION_VERSION'
value: '~4'
}
{
name: 'WEBSITE_NODE_DEFAULT_VERSION'
value: '~14'
}
{
name: 'FUNCTIONS_WORKER_RUNTIME'
value: runtime
}
]
ftpsState: 'FtpsOnly'
minTlsVersion: '1.2'
}
httpsOnly: true
}
}