1

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?

Sandeep Thomas
  • 4,303
  • 14
  • 61
  • 132
  • 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? – Jonesopolis Jul 13 '22 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 – Sandeep Thomas Jul 13 '22 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". – rekcul Jul 13 '22 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" – rekcul Jul 13 '22 at 14:42
  • @rekcul Its like that according to the documentation (https://devblogs.microsoft.com/azure-sdk/introducing-the-new-azure-function-extension-libraries-beta/). Its the prefix we specified in the local settings connection – Sandeep Thomas Jul 13 '22 at 14:44
  • @rekcul Thanks man.. But if so how can we tell the trigger to monitor which blob. When I did that as you said the connection as empty it is not triggering that error. But how the trigger will identity which blob it is? – Sandeep Thomas Jul 13 '22 at 14:46
  • See my answer below. Basically if you keep the connection empty, it will use what ever is defined in the AzureWebJobsStorage variable in your local.settings.json. If you want to have two or more blob triggers on different blobs, you should define the different blob storages in your local.settings.json with unique identifiers and use those in your "connection" attribute in the blob trigger – rekcul Jul 13 '22 at 14:58

1 Answers1

1

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"
rekcul
  • 319
  • 1
  • 7
  • 18
  • 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. – Sandeep Thomas Jul 13 '22 at 16:06
  • 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. – rekcul Jul 14 '22 at 06:15