簡體   English   中英

Azure function 連接到 Azure Vnet 問題后的 Blob 存儲

[英]Azure function connection to Azure Blob storage behind Vnet issue

我們目前正在遷移到新的 Azure 訂閱,並且在執行 Azure 功能時遇到問題,這些功能在我們的舊 Azure 訂閱中按預期工作。 我們的舊訂閱和新訂閱之間的差異在於我們已經建立了一個帶有子網的虛擬網絡,並在子網后面部署了我們的資源。

我們還必須從舊訂閱中的 Azure 應用服務遷移到新訂閱中的 Azure 應用環境。

我們的 Azure 環境包括:

應用服務環境

應用服務計划 I1

Azure 應用環境和存儲容器在同一個虛擬網絡上,但在不同的子網上。 Function 使用在存儲帳戶上具有所有者角色的托管身份。

下面列出的代碼在我們不包含虛擬網絡的舊環境中運行良好,但在我們的新環境中失敗。

任何指導將不勝感激。

The Azure function which connects to Azure Storage works when run locally from Visual Studio 2019, but fails when run from Azure portal.

代碼片段如下:

This section works just fine:

     string storageConnectionString = XXXXConn.ConnectionETLFileContainer();//Get Storage connection string

                var myDirectory = "XXXX/Uploads"; ///XXXX-etl-file-ingest/ABSS/Uploads/                     CloudStorageAccount storageAccount = CloudStorageAccount.Parse(storageConnectionString);

                CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();// Create a CloudBlobClient object for credentialed access to Azure Blob.                                      CloudBlobContainer blobContainer = blobClient.GetContainerReference("XXXX-etl-blobfile-ingest");// Get a reference to the Blob Container we created previously.                                      CloudBlobDirectory blobDirectory = blobContainer.GetDirectoryReference(myDirectory);// Get a reference to the Blob Directory.

                var blobs = blobDirectory.ListBlobs(useFlatBlobListing: true); //set useFlatBlobListing as true 

此語句失敗:嘗試遍歷 Blob 文件並獲取特定文件信息時發生故障。

foreach (var myblob in blob)

在 azure 門戶打開存儲帳戶刀片下 go 到配置刀片,您將能夠看到您的存儲帳戶允許訪問的網絡列表。一旦您擁有允許的網絡列表,請檢查 ZC1C425268E617A74D 上是否存在如果不是其中一個網絡,那么您需要將托管 function 應用程序的網絡添加到列表中。

更新 2:
我發現的最簡單的解釋/原因是,當應用服務或 Function 應用的設置WEBSITE_VNET_ROUTE_ALL設置為1時,到公共端點的所有流量都被阻止。 因此,如果您的存儲帳戶沒有配置專用端點,對它的請求將失敗。

文檔:“要阻止到公共地址的流量,您必須將應用程序設置 WEBSITE_VNET_ROUTE_ALL 設置為 1。”
https://docs.microsoft.com/en-us/azure/app-service/web-sites-integrate-with-vnet.network-security-groups

更新1:
我在下面的回答只是解決我的問題的方法。 原來我沒有將私有 DNS 區域(這是在您創建新的私有端點時為您創建的)鏈接到我的 VNET。

為此,go 到 Azure 門戶中的私有 DNS 區域,然后單擊左側菜單欄中的Virtual network links 向您的 Function 集成的 VNET 添加一個新鏈接。

這可能與 OP 無關,但希望它能對其他人有所幫助。


原答案:
在我的情況下,這是通過在應用服務的子網(專用子網)上啟用Microsoft.Storage服務端點來解決的。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM