由于我们是 Azure Function App 的新手,我们听说它的一大功能是可扩展性,但是 azure function scale 是如何实现的呢?它是在后面自动缩放还是我们可以设置任何机制?例如,最大比例尺寸限制。
当我们在本地调试 azure 函数时(我们尝试了ServiceBusTrigger、EventHubTrigger、QueueTrigger 和 CosmosDBTrigger),似乎每次在我们继续发送消息时都会一遍又一遍地调用同一个函数实例,这无法实现扩展/正如我们所期望的并行工作,有什么好的方法可以在本地调试可扩展性吗?
azure azure-functions azure-functions-runtime azure-function-app
您好,我正在编写 Azure 函数触发器来捕获 cosmosdb 的更改。我面临着一个基本问题。
在 function.json 中,我想保持以下参数动态(应该从环境变量中选取)。原因是同一个应用程序将部署在多个环境中,并且它们可能具有不同的数据库名称。
"databaseName": "CosmosDbName",
"collectionName": "UserCollectionName",
Run Code Online (Sandbox Code Playgroud)
我尝试在 local.settings.json 中设置值来测试它,但失败并且没有选择值。
有什么建议 ?
找到了解决方案
"databaseName": "%CosmosDbName%",
"collectionName": "%UserCollectionName%",
Run Code Online (Sandbox Code Playgroud) 我目前有一个带有计时器触发器的 .NET Core 2.1 Azure Functions 应用程序。由于网络格局发生变化,Azure 中的函数应用不再具有对其所需数据库资源的网络访问权限。我们曾考虑将应用程序重新指向 Web 服务而不是数据库,但在短期内需要一个直接迁移的解决方案,并且我们有一个内部部署的服务器,用于运行批处理作业控制台应用程序。
有没有什么简单的方法可以通过命令行运行 Azure Functions 应用程序? 它似乎从 Visual Studio 调试器中以这种方式工作。
console-application .net-core .net-core-2.1 azure-function-app
遵循微软文档(https://docs.microsoft.com/en-us/azure/azure-functions/functions-create-function-linux-custom-image?tabs=bash%2Cportal&pivots=programming-language-python)但是用于Azure Blob 存储触发器模板。
当我运行 docker run -p 8080:80 -it example/azurefunctionsimage:v1.0 时出现以下错误,
fail: Host.Startup[402]
fail: Host.Startup[402]
The 'voice-text' function is in error: Microsoft.Azure.WebJobs.Host: Error indexing method 'Functions.voice-text'. Microsoft.Azure.WebJobs.Extensions.Storage: Storage account connection string 'AzureWebJobsStorage' does not exist. Make sure that it is a defined App Setting.
Hosting environment: Production
Content root path: /
Now listening on: http://[::]:80
Application started. Press Ctrl+C to shut down.
info: Host.General[316]
Host lock lease acquired by instance ID '0000000000000000000000000'.
warn: Microsoft.Azure.WebJobs.Script.ChangeAnalysis.ChangeAnalysisService[0]
Breaking change analysis …Run Code Online (Sandbox Code Playgroud) azure docker azure-blob-storage azure-functions-core-tools azure-function-app
我在 Powershell 中编写了一个程序,该程序在 Azure Functions 应用程序中按计划运行。为了避免硬编码凭据,我创建了一个 Azure Key Vault 来存储机密。我在 Azure Function 中创建了一个托管标识,在 Azure Key Vault 中创建了机密,然后在 Azure Function 中创建了应用程序设置,使用 URL 指向 Azure Key Vault 中的机密。该程序引用应用程序机密 (APPSETTING) 并按预期运行:
$uSecret = $ENV:APPSETTING_SecretUsername
$pSecret = $ENV:APPSETTING_SecretPassword
$sasSecret = $ENV:APPSETTING_SecretSAS
$securePassword = ConvertTo-SecureString -String $pSecret -AsPlainText -Force
$UserCredential = New-Object -TypeName "System.Management.Automation.PSCredential" -ArgumentList $uSecret, $securePassword
$session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection
Run Code Online (Sandbox Code Playgroud)
但是我注意到,如果我通过 Windows Powershell(以管理员身份运行)在我的本地计算机上运行相同的程序,并按如下方式修改上述行,程序运行良好 - 这意味着它可以访问 Office 365 和数据湖存储:
$uSecret = (Get-AzKeyVaultSecret -VaultName 'auditkeyvault' -Name 'SecretUsername').SecretValueText
$pSecret …Run Code Online (Sandbox Code Playgroud) 问题大纲
Azure Function App 集成到 VNET 后无法访问,并且 WEBSITE_VNET_ROUTE_ALL 设置为 1。
这是必需的,以便 Function App 可以安全地连接到 SQL,而无需公开 SQL。
错误:
无法列出功能应用程序键。
来自同一网络中 VM 的 HTTP 请求 (CURL) 失败:504 网关超时
架构图
重现步骤
我正在尝试部署一个简单的 powershell 函数应用程序,其中包含以下命令:
Import-Module D:\home\site\wwwroot\HttpTrigger1\AzureAD\AzureAD.psd1
Connect-AzureAD -TenantId $tenantId -Credential $Credential
Run Code Online (Sandbox Code Playgroud)
AzureAD 模块文件已使用 KUDU 从本地存储库“C:\Program Files\WindowsPowerShell\Modules\AzureAD”复制到“D:\home\site\wwwroot\HttpTrigger1\AzureAD”。
在 Import-Module 行出错,这里是 ERROR 堆栈跟踪:
ERROR: Could not load file or assembly 'System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. The system cannot find the file specified.Exception :Type : System.IO.FileNotFoundExceptionMessage : Could not load file or assembly 'System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. The system cannot find the file specified.FileName : System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089TargetSite :Name : GetExportedTypesDeclaringType : System.Reflection.RuntimeAssembly, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798eMemberType : MethodModule : System.Private.CoreLib.dllStackTrace :at System.Reflection.RuntimeAssembly.GetExportedTypes()at System.Reflection.Assembly.get_ExportedTypes()at …Run Code Online (Sandbox Code Playgroud) powershell azure-powershell azure-functions azure-function-app
我有在本地运行的 powershell 脚本。但是那些脚本没有运行现场函数应用程序 > powershell (windows) 机器。
az login --service-principal -u $ServicePrincipalId -p $ServicePrincipalPass --tenant $ServicePrincipalTenant
当我运行脚本时得到下面
ERROR: The term 'az' is not recognized as the name of a cmdlet, function, script file, or operable program.
Run Code Online (Sandbox Code Playgroud)
因为我没有在 Windows 机器上安装 az cli,所以我在我的脚本中添加了以下行来安装 az 命令。
Install-Module -Name Az -AllowClobber -Scope CurrentUser
Run Code Online (Sandbox Code Playgroud)
安装 az 时出现访问问题。
2019-06-11T12:42:59.698 [Warning] WARNING: InternalWebProxy: Could not find a part of the path 'D:\Program Files (x86)\SiteExtensions\Functions\2.0.12507\32bit\workers\powershell\runtimes\win-x86\lib\netcoreapp2.1\ref'.
2019-06-11T12:42:59.843 [Warning] WARNING: Win32Helpers: Could not find a part of the path 'D:\Program …Run Code Online (Sandbox Code Playgroud) 我在我的 DevOps 中为函数应用程序创建了一个发布管道。它具有测试部署阶段(手动触发)和产品部署触发器设置为“阶段后测试”。它还设置了部署前批准。手动触发释放(多个阶段)。测试已部署,但生产阶段只是排队。我也没有看到任何进行批准的选项。如何让产品也部署而不仅仅是排队?我错过了什么吗,请帮忙吗?截图会更有意义,附上 devops 的截图 -
产品部署前批准
产品排队的发布屏幕截图 -
azure-devops azure-pipelines-release-pipeline azure-function-app
我正在本地构建 .NET Core 3.1 Azure Functions 应用程序,并尝试配置启动类。当我实现一个要继承的类时,FunctionsStartup我无法将 .net core 3.1 类库导入到我的项目中。如果我这样做并尝试运行该应用程序,我会在执行窗口中收到以下错误:
Microsoft.Azure.Functions.Extensions: Method not found: Microsoft.Extensions.Configuration.IConfigurationBuilder Microsoft.Azure.WebJobs.Hosting.IWebJobsConfigurationBuilder.get_ConfigurationBuilder()'. Value cannot be null. (Parameter 'provider')
当我将 Startup 基类切换到IWebJobsStartup应用程序时,启动正常。当我提出请求并尝试单步执行代码时,我遇到了问题。我可以单步执行代码的初始部分(所以我知道我的请求已成功接收),但我无法单步执行我的其中一个功能。我收到一个下载提示,并在 VS 工作区中打开一个页面,其中包含TaskMethodInvker.cs not found带有标记行的错误消息You need to find TaskMethodInvoker.cs to view the source for the current call stack frame。下面的代码显示了我的功能:
[FunctionName("HttpAuth")]
public async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req,
ExecutionContext context,
ILogger log)
{
GetAzureADConfiguration(context);
var jwt = GetJwtFromHeader(req);
}
private JwtSecurityToken GetSecurityToken(string encodedToken) …Run Code Online (Sandbox Code Playgroud) 我们知道可以从local.setting.json文件使用事件中心的Connection字符串。因此,对于不同环境中的同一功能应用程序,我可以在azure门户的“应用程序设置”中添加事件中心连接字符串设置。
由于EventHubTrigger函数应用程序还将事件名称和使用者组(可选)用作属性参数,我想知道如何从应用程序设置中使用事件中心名称和使用者组?
public static void EventHubTriggerFunc([EventHubTrigger("myeventhubname", Connection = "EventHubConnectionAppSetting", ConsumerGroup = "myconsumergroupname")] EventData myEventHubMessage, DateTime enqueuedTimeUtc, Int64 sequenceNumber, string offset, ILogger log)
{
// Here EventHubConnectionAppSetting is specified in local.setting.json file
//myeventhubname & myconsumergroupname are hard coded string
}
Run Code Online (Sandbox Code Playgroud)
本地设置
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"FUNCTIONS_WORKER_RUNTIME": "dotnet",
"EventHubConnectionAppSetting": "Endpoint=.....",
"EventHubConsumerGroup": "myconsumergroup"
}
}
Run Code Online (Sandbox Code Playgroud) 我需要一个 Azure Functions blob 触发器来触发应用设置在运行时提供的存储桶。我读到可以这样做:
[FunctionName("Process")]
public static async Task Process([BlobTrigger("%BucketName%/{name}", Connection = "AzureWebJobsStorage")] Stream avroBlobStream, string name, TraceWriter log)
{
}
Run Code Online (Sandbox Code Playgroud)
如果我BucketName只有Values在 appsettings.json的字段中,这在本地工作。
{
"IsEncrypted": false,
"Values": {
"BucketName": "capture-bucket",
}
}
Run Code Online (Sandbox Code Playgroud)
如果它不在 Values 字段中,则这是错误:
[6/24/2019 5:52:15 PM] Function 'SomeClass.Process' failed indexing and will be disabled.
[6/24/2019 5:52:15 PM] No job functions found. Try making your job classes and methods public. If you're using binding extensions (e.g. ServiceBus, Timers, etc.) make sure you've called the …Run Code Online (Sandbox Code Playgroud) 我按照文档设置了运行时版本 V3 的应用程序函数,但它抛出了 InternalServerError。如何创建与 V3 一起使用的应用程序功能?这是我的步骤:
错误:在主机运行时遇到错误 (InternalServerError)
我尝试在函数应用程序设置中选择运行时版本 ~2,但运行时版本显示“正在加载...”,如果我退出并返回到此函数,它会显示 ~2 为选定状态,但 InternalServerError 继续显示并且运行时版本显示“正在加载...”
如果我更改为版本 ~1,它会显示运行时版本 1.012967.0。但我无法改回V3,因为它再次显示internalServerError。
根据文档“函数应用程序是在运行时的 2.x 版本中创建的”,但当我第一次创建该函数时,它似乎是在 V1 中创建的?Kudu 在 home/LogFiles/eventlog.xml 中显示“Provider Name="IIS AspNetCore Module V2"/”
后来我尝试将我的 VS 代码部署到这个函数应用程序中,并在 VS 和门户中使用 V3 函数,但这当然行不通。并且在门户中使用 V1 从 VS 部署 V3 并不是文档建议的过程尽管运行时版本由 FUNCTIONS_EXTENSION_VERSION 设置确定,但您应该在 Azure 门户中进行此更改,而不是直接更改设置”建议的过程。
最后,如果我尝试从 VS 创建应用程序功能,它会自动使用 V2 创建它,并且在检查门户时我会得到相同的内部服务器错误。它仅适用于 V1 1.0.12967.0 (~1)。
非常感谢帮助
azure ×6
powershell ×3
.net-core ×2
c# ×2
appsettings ×1
azure-cli ×1
azure-devops ×1
azure-pipelines-release-pipeline ×1
c#-4.0 ×1
docker ×1
security ×1
sql-server ×1
vnet ×1