CodexBloom - Programming Q&A Platform

Azure Functions: how to to Access Blob Storage due to 'BlobNotFound' scenarios with Service Principal Authentication

👀 Views: 72 đŸ’Ŧ Answers: 1 📅 Created: 2025-06-14
azure-functions blob-storage managed-identity azure-storage csharp

I tried several approaches but none seem to work. I need some guidance on Hey everyone, I'm running into an issue that's driving me crazy... I'm working on an Azure Function that processes files from a Blob Storage account. I'm using a managed identity for authentication and the Azure.Storage.Blobs library (version 12.10.0). Despite having correctly set up the permissions for the managed identity in the Azure portal, I keep working with a 'BlobNotFound' behavior. Here's the code I'm using to access the blob: ```csharp using Azure.Storage.Blobs; using Azure.Identity; public static async Task Run(string myQueueItem, ILogger log) { string blobServiceEndpoint = "https://<myaccount>.blob.core.windows.net"; string containerName = "my-container"; string blobName = myQueueItem; var client = new BlobServiceClient(new Uri(blobServiceEndpoint), new DefaultAzureCredential()); var containerClient = client.GetBlobContainerClient(containerName); var blobClient = containerClient.GetBlobClient(blobName); try { var response = await blobClient.DownloadAsync(); using (var streamReader = new StreamReader(response.Value.Content)) { string content = await streamReader.ReadToEndAsync(); log.LogInformation(content); } } catch (Azure.RequestFailedException ex) { log.LogError($"behavior accessing blob: {ex.Message}"); } } ``` I've verified that the blob name passed in `myQueueItem` is correct and corresponds to an existing file in the specified container. The managed identity has been granted 'Storage Blob Data Reader' role on the container. However, I still receive the behavior: ``` Azure.RequestFailedException: BlobNotFound: The specified blob does not exist. ``` I've checked the Blob Storage and confirmed the blob is indeed there. Is there anything I'm missing regarding the setup of the managed identity or the way I'm constructing the blob storage client? Any help or insights would be greatly appreciated! My development environment is Linux. Am I missing something obvious? Is there a better approach? I've been using Csharp for about a year now. Any advice would be much appreciated.