大佬教程收集整理的这篇文章主要介绍了【Azure 应用服务】Azure Function集成虚拟网络,设置被同在虚拟网络中的Storage Account触发,遇见Function无法触发的问题,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
一切为了安全,所有的云上资源如支持内网资源访问,则都可以加入虚拟网络
使用Azure Function处理Storage Account中Blob 新增,更新,删除等情况。Storage Account启用虚拟网络中的服务终结点(service Endpoint)后,可以实现只能从内网访问。同时,Azure Function也支持集成内网。并且可支持在虚拟网络中被Storage Account所触发。所以根据门户中一步一步的操作,配置完Azure Function和Storage Account的Virtul Network后,发现Function无法启动。在日志中发现问题是:
2021-06-30T10:56:00.895 [Error] An unhandled exception has occurred. Host is shutTing down. @H_82_14@microsoft.Azure.Storage.StorageException : This request is not authorized to perform this operation. at async Microsoft.Azure.Storage.Core.Executor.Executor.ExecuteAsync[T](RESTCommand`1 cmd,IRetryPolicy policy,OperationContext operationContext,CancellationToken token) at System.Runtime.Exceptionservices.ExceptionDispatchInfo.Throw() at async Microsoft.Azure.WebJobs.Extensions.Storage.TimeoutHandler.ExecuteWithTimeout[T](String operationName,String clientrequestId,IWebJobsExceptionHandler exceptionHandler,ILogger logger,CancellationToken cancellationToken,Func`1 operation) at C:projectsazure-webjobs-sdk-rqm4tsrcMicrosoft.Azure.WebJobs.Extensions.StorageTimeoutHandler.cs : 56 at System.Runtime.Exceptionservices.ExceptionDispatchInfo.Throw() at async Microsoft.Azure.WebJobs.Host.Queues.Listeners.QueueListener.ExecuteAsync(CancellationToken cancellationToken) at C:projectsazure-webjobs-sdk-rqm4tsrcMicrosoft.Azure.WebJobs.Extensions.StorageQueuesListenersQueueListener.cs : 201 at System.Runtime.Exceptionservices.ExceptionDispatchInfo.Throw() at async Microsoft.Azure.WebJobs.Host.Timers.TaskSeriesTimer.RunAsync(CancellationToken cancellationToken) at C:projectsazure-webjobs-sdk-rqm4tsrcMicrosoft.Azure.WebJobs.HostTimersTaskSeriesTimer.cs : 147 2021-06-30T10:56:00.921 [Information] Stopping JobHost 2021-06-30T10:56:00.921 [Information] Stopping the listener 'Microsoft.Azure.WebJobs.Host.Listeners.CompositeListener' for function 'Blobtrigger1' 2021-06-30T10:56:00.942 [Information] Stopped the listener 'Microsoft.Azure.WebJobs.Host.Listeners.CompositeListener' for function 'Blobtrigger1' 2021-06-30T10:56:00.943 [Information] Job host stopped
(日志可通过高级工具Kudu获取:Kudu地址为:https://<your function app name>.scm.chinacloudsites.cn/DebugConsole 日志路径为:D:homeLogFilesApplicationFunctionsHostxxxxxxxx.log)
根据日志发现了:
1) Function Host遇见了异常,导致它被关闭.
2)异常的原因是因为访问Storage没有权限 (@H_82_14@microsoft.Azure.Storage.StorageException : This request is not authorized to perform this operation.)
那么问题根源就出现在Azure Function访问Stroage时,走的是公网访问,而公网的访问在Storage中式拒绝的。所以要修改Funciton的配置,让其通过内网的形式访问Storage。在查看官方说明文档后,有发现两个非常重要的配置:
在Azure Funciton的设置页面,添加WEBSITE_VNET_ROUTE_ALL和WEBSITE_DNS_SERVER两个参数,配置如下:
修改完成后,再次查看Function Host的启动日志,就可见 “Loading functions metadata” 和 “1 functions loaded”等消息。这就表明,Function Host启动成功。
2021-06-30T10:57:00.006 [Information] Initializing Warmup Extension. 2021-06-30T10:57:00.069 [Information] Initializing Host. OperationId: '93cf4ed0-d598-4308-9241-dca5ba6a55ee'. 2021-06-30T10:57:00.073 [Information] Host initialization: ConsecutiveErrors=0, StartupCount=1, OperationId=93cf4ed0-d598-4308-9241-dca5ba6a55ee 2021-06-30T10:57:00.106 [Information] LoggerFilterOptions { "@H_55_97@minLevel": "None", "Rules": [ { "ProviderName": null, "CategoryName": null, "LogLevel": null, "Filter": "<AddFilter>b__0" }, { "ProviderName": "@H_55_97@microsoft.Azure.WebJobs.Script.WebHost.Diagnostics.SystemLoggerProvider", "CategoryName": null, "LogLevel": "None", "Filter": null }, { "ProviderName": "@H_55_97@microsoft.Azure.WebJobs.Script.WebHost.Diagnostics.SystemLoggerProvider", "CategoryName": null, "LogLevel": null, "Filter": "<AddFilter>b__0" } ] } 2021-06-30T10:57:00.107 [Information] FunctionResultAggregatorOptions { "BatchSize": 1000, "FlushTimeout": "00:00:30", "IsEnabled": true } 2021-06-30T10:57:00.107 [Information] SingletonOptions { "LockPeriod": "00:00:15", "ListenerLockPeriod": "00:00:15", "LockAcquisitionTimeout": "10675199.02:48:05.4775807", "LockAcquisitionPollingInterval": "00:00:05", "ListenerLockRecoveryPollingInterval": "00:01:00" } 2021-06-30T10:57:00.107 [Information] QueuesOptions { "BatchSize": 16, "NewBatchThreshold": 8, "@H_55_97@maxPollingInterval": "00:00:02", "@H_55_97@maxDequeueCount": 5, "VisibilityTimeout": "00:00:00" } 2021-06-30T10:57:00.107 [Information] BlobsOptions { "CentralizedPoisonQueue": false } 2021-06-30T10:57:00.108 [Information] StarTing JobHost 2021-06-30T10:57:00.110 [Information] StarTing Host (HostId=lbfunctionforvnet01, InstancEID=05efd41a-013d-428c-b839-fb4b69127366, Version=3.0.15733.0, ProcessId=5480, AppDomainId=1, InDebugMode=True, InDiagnosticMode=false, FunctionsExtensionVersion=~3) 2021-06-30T10:57:00.121 [Information] Loading functions metadata 2021-06-30T10:57:00.137 [Information] 1 functions loaded 2021-06-30T10:57:01.348 [Information] GeneraTing 1 job function(s) 2021-06-30T10:57:01.373 [Information] Found the following functions: Host.Functions.blobtrigger1
最后在Storage Blob中上传文件进行测试,Function能成功被触发及获取到正确的Blob信息
2021-06-30T11:02:22.273 [Information] ExecuTing 'Functions.blobtrigger1' (Reason='New blob detected: samples-workitems/local_error.log', Id=79bc13b9-5aed-487f-b5de-02bb4ff7b8c6) 2021-06-30T11:02:22.276 [Information] trigger Details: messagEID: f6dd9893-f6c6-41af-a469-f6b2e21e09bc, DequeueCount: 1, InsertionTime: 2021-06-30T11:02:22.000+00:00, BlobCreated: 2021-06-30T11:02:13.000+00:00, BlobLastModified: 2021-06-30T11:02:13.000+00:00 2021-06-30T11:02:22.283 [Information] C# Blob trigger function Processed blob Name:local_error.log Size: 420588 Bytes 2021-06-30T11:02:22.291 [Information] Executed 'Functions.blobtrigger1' (Succeeded, Id=79bc13b9-5aed-487f-b5de-02bb4ff7b8c6, Duration=37ms)
具有虚拟网络触发器的高级计划 :https://docs.azure.cn/zh-cn/azure-functions/functions-networking-options#premium-plan-with-virtual-network-triggers
配置函数应用设置:https://docs.azure.cn/zh-cn/azure-functions/functions-create-vnet#configure-your-function-app-setTings
以上是大佬教程为你收集整理的【Azure 应用服务】Azure Function集成虚拟网络,设置被同在虚拟网络中的Storage Account触发,遇见Function无法触发的问题全部内容,希望文章能够帮你解决【Azure 应用服务】Azure Function集成虚拟网络,设置被同在虚拟网络中的Storage Account触发,遇见Function无法触发的问题所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。