2

I am trying to implement Azure Blob trigger for our ADLS2 container directory. I am following these two MS docs for that

Azure Blob storage trigger for azure functions

Azure function extension libraries

So here is our local.settings.json

{
  "IsEncrypted": false,
  "Values": {
    "FUNCTIONS_WORKER_RUNTIME": "dotnet",
    "AzureWebJobsStorage": "UseDevelopmentStorage=true",
    "myconnection__blobServiceUri": "https://myadls2account.blob.core.windows.net",
    "myconnection__queueServiceUri": "https://myadls2account.blob.core.windows.net"
  }
}

And here is our blob trigger

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

But when executing it triggers the below error

Error indexing method 'Function1'
Microsoft.Azure.WebJobs.Host: Error indexing method 'Function1'. Microsoft.Azure.WebJobs.Extensions.Storage: Storage account connection string 'AzureWebJobsmyconnection' does not exist. Make sure that it is a defined App Setting.

enter image description here

Please share your thoughts what did I missed or what I did wrong?

7
  • I'm not too savvy on these triggers, but the error seems straight forward. Have you tried creating an app setting at the root level with the name it's expecting? Commented Jul 13, 2022 at 14:30
  • But the solution we are trying is to get rid of connection string and to use azure active directory identity. And for the function to use Azurite I have specified UseDevelopmentStorage=true Commented Jul 13, 2022 at 14:37
  • I think it is just a naming issue. In your blobtrigger you define the connection as "myconnection". In your local settings there is no connection string named "myconnection". Try to change the connection in your blobtrigger to "AzureWebJobsStorage". Commented Jul 13, 2022 at 14:38
  • 1
    Btw, the first link you posted describes it very well: "If the app setting name begins with "AzureWebJobs", you can specify only the remainder of the name here. For example, if you set connection to "MyStorage", the Functions runtime looks for an app setting that is named "AzureWebJobsMyStorage." If you leave connection empty, the Functions runtime uses the default Storage connection string in the app setting that is named AzureWebJobsStorage" Commented Jul 13, 2022 at 14:42
  • @rekcul Its like that according to the documentation (devblogs.microsoft.com/azure-sdk/…). Its the prefix we specified in the local settings connection Commented Jul 13, 2022 at 14:44

1 Answer 1

2

You have a naming issue in your blobtrigger:

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

As per your code, you defined connection as "myconnection". So the runtime is looking for a key "myconnection" in your local.settings.json. If this key is not available, it will look for "AzureWebJobsmyconnection".

So there are several solutions now:

  1. Add a "myconnection" key to the local.settings.json
  2. Add a AzureWebJobsmyconnection" key to the local.settings.json
  3. Keep the connection in your blob trigger empty to force the runtime to use the default key "AzureWebJobsStorage"

Of course it is possible to define several different variables in the local.settings.json for different blob triggers. So something like this:

"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"MyFirstBlob": "{first}",
"MySecondBlob": "{second}"

and then use those in your blob trigger connections

Connection = "MyFirstBlob" or connection = "MySecondBlob"
Sign up to request clarification or add additional context in comments.

2 Comments

The problem when leaving connection as empty, ofcouse the AzureWebJobsStorage will get considered. And its working fine when uploading files to my local storage emulator directory. But what I am trying is to trigger when there is any insertion into my cloud directory. In the service dependencies as well my cloud storage showing as connected. Kindly note I am trying to trigger file changes in ADLS2 storage while executing the function in local storage and using Active Directory Identity instead of using connection strings.
What do you mean by "executing the function in local storage"? Do you want the blob trigger to add/change/remove data in your local storage? In general: If you are in debug the function is executed in your debug runtime, if you push your functions into a function app it is going to be executed in the azure function app runtime. The blob (in your case the ADLS2) the function is connected with, is defined in your connection attribute in the blob trigger.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.