pythonazureazure-functionsazure-blob-storageazure-function-app

Azure Function using Python - Blob trigger not firing


I am working on one of the Azure Function which is written in Python and it should get called based on Blob trigger event. However, the trigger is not firing when I am uploading a zip file in a blob container to which azure function is supposed to monitor.

Following is local.settings.json file -

{
  "IsEncrypted": false,
  "Values": 
    {
    "AzureWebJobsStorage": "blob (connection string) that was created when Azure function is created",
    "FUNCTIONS_WORKER_RUNTIME": "python",
    "My_STORAGE": "blob (connection string) that function should monitor"
    }
} 

Following is function.json file -

{
  "scriptFile": "__init__.py",
  "bindings": [
    {
      "name": "myblob",
      "type": "blobTrigger",
      "direction": "in",
      "path": "mycontainer/{name}",
      "connection": "My_STORAGE"
    }
  ]
}

Following is my code init.py - (test_func is user defined function to do some business logic)

def main(myblob: func.InputStream):
test_func(myblob.name)
logging.info(f"Python blob trigger function processed blob \n"
             f"Name: {myblob.name}\n"
             f"Blob Size: {myblob.length} bytes")

When I'm uploading zip file in "mycontainer" container, the azure function is not firing.

The "mycontainer" of StorageV2 (general purpose v2) account kind. I am using Python 3.8 version.

This "mycontainer" has automatically created a container named $logs that has day wise folder to have a log file mentioning the file that I'm uploading in "mycontainer", however, there is no sign of blob trigger event on Azure function.

"My_STORAGE" is added as Application Settings in Azure Function's Configuration settings. I am uploading Local Settings after Azure Function deployment.

Any idea what is going wrong?

Thank you.


Solution

  • The problem was caused by mistake in connection string. The AccountName in connection string should be storage account name but not the name of container.

    So just change AccountName=mycontainer to AccountName=<storage account name>, then it works.

    And by the way:

    The connection string should be: DefaultEndpointsProtocol=https;AccountName=<storage account name>;AccountKey=xxxxxxxxxx==;EndpointSuffix=core.windows.net

    The "path" in "function.json" should be: "path": "<container name>/{name}"