Azure Blobtrigger function - InvalidResourceName

93 views Asked by At

In Azure, I'm setting up an Azure Function with a blobtrigger, it uses a SAS connectionstring to a blobstorage account in the same subscription, in the same resource group. When starting the function, in either the logstream in kudu or app insights, I get the following exception: Azure.RequestFailedException: at Azure.Storage.Queues.QueueRestClient+<GetPropertiesAsync>d__14.MoveNext (Azure.Storage.Queues, Version=12.14.0.0, Culture=neutral, PublicKeyToken=92742159e12e44c8) at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) at Azure.Storage.Queues.QueueClient+<GetPropertiesInternal>d__61.MoveNext (Azure.Storage.Queues, Version=12.14.0.0, Culture=neutral, PublicKeyToken=92742159e12e44c8) at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) at Azure.Storage.Queues.QueueClient+<ExistsInternal>d__52.MoveNext (Azure.Storage.Queues, Version=12.14.0.0, Culture=neutral, PublicKeyToken=92742159e12e44c8) at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) at Azure.Storage.Queues.QueueClient+<ExistsAsync>d__51.MoveNext (Azure.Storage.Queues, Version=12.14.0.0, Culture=neutral, PublicKeyToken=92742159e12e44c8) at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) at Microsoft.Azure.WebJobs.Extensions.Storage.Common.Listeners.QueueListener+<ExecuteAsync>d__34.MoveNext (Microsoft.Azure.WebJobs.Extensions.Storage.Blobs, Version=5.2.0.0, Culture=neutral, PublicKeyToken=92742159e12e44c8) at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) at Microsoft.Azure.WebJobs.Extensions.Storage.Common.Timers.TaskSeriesTimer+<RunAsync>d__14.MoveNext (Microsoft.Azure.WebJobs.Extensions.Storage.Blobs, Version=5.2.0.0, Culture=neutral, PublicKeyToken=92742159e12e44c8)

So right now there are a few different environments in play, Local developmnet, env X, dev, test and sandbox. When developing on my local machine, everything works and runs fine, no problems. X is an environment I deployed using publish in Visual Studio, works perfectly fine. Dev, test, sandbox are deployed through bicep pipelines through devops, all three of these have the same problem.

Dev, test, sandbox and X are all in the same azure subscription.

To me it looks like the function can get to the blob storage, something somewhere goes wrong with the QueueRestClient, he gets an error he can't parse and thus returns an errormessage that's not really relevant to the problem.

Code for the trigger function:

public async Task Run([BlobTrigger("drop/{name}.csv")] Stream stream, string name)


The things I've tried

  • It used to only be dev and test, setup at the start of the project, once I found out those weren't working I deployed sandbox when the code was fully realised, hoping (because there was no tinkering while during development) that it would magically work. But now, instead of 2 non-working environments, I have 3.

  • Because env X worked, I tried changing the connectionstring from the X blob storage to the dev blob storage

    • X kept working fine when dropping a file.
  • When changing the connectionstring from dev to use the X blob storage

    • Still didn't work, gave the same error.
  • When adding a HttpTrigger function to the same function project

    • Function is pingable and works fine.
  • Adding a second blob trigger function which does nothing more than logging something when a file is dropped (so no complex logic)

    • Same error as the "real" function.
  • Use 2 separate blob storage containers since one of my colleagues suggested it

    • No difference, same error as before
  • Use managed identity instead of SAS

    • No difference, same error as before
  • Double, tripple, quadruple check, use notepad++ text compare to make sure the connectionstrings area correct

  • Put connectionstrings in the configuration instead of keyvault references

    • No difference, same error as before
    • And purposefully putting in a wrong connectionstring tells me that the function does read the connectionstring correctly
  • Checked if dev and test have the same host id and lock eachother out

    • Checked and not the case
  • Checked each and every setting between the dev function and X function

    • All settings are the same except:
      • Service plan settings, scale up, scale out
        • Don't know enough about this to be 100% sure, but I doubt this would be the culprit
      • Dev has a system assigned identity, X does not
        • We're using SAS, so identity shouldn't matter and even if it'd matter, X should be the one to fail
  • Is the file that's being uploaded invalid

    • The function crashes before it's even able to get to the file
2

There are 2 answers

0
Dries Van Hertbruggen On BEST ANSWER

Solution has been found, it didn't have anything to do with the code or the setup. Turns out the problem was that the FunctionHostID contained uppercase letters, which isn't allowed accorging to the documentation.

https://learn.microsoft.com/en-us/azure/azure-functions/functions-app-settings#azurefunctionswebhost__hostid

enter image description here

1
Ikhtesam Afrin On

I have created a default Blob Trigger function in visual studio and my function code looks like below-

public class Function1
{
    [FunctionName("Function1")]
    public void Run([BlobTrigger("demo/{name}", Connection = "BlobConnectionString")]Stream myBlob, string name, ILogger log)
    {
        log.LogInformation($"C# Blob trigger function Processed blob\n Name:{name} \n Size: {myBlob.Length} Bytes");
    }
}

I have copied the connection string from below and added in local.settings file for local development.

enter image description here

{
    "IsEncrypted": false,
  "Values": {
    "AzureWebJobsStorage": "UseDevelopmentStorage=true",
    "FUNCTIONS_WORKER_RUNTIME": "dotnet",
    "BlobConnectionString": "DefaultEndpointsProtocol=https;AccountName=afrinstore01;AccountKey=*********;EndpointSuffix=core.windows.net"
  }
}

My .csproj contains below packages.

<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.Storage" Version="5.2.1" />
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="4.2.0" />

I able to get the successful result as shown below

enter image description here

I deployed my function to function app and then added connection string in Configuration blade like below-

enter image description here

I am able to get the expected output post uploading a file in my container.

enter image description here

Please check if you have added the connection string in the Configuration blade post deployment.