1
votes

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.

2
Did you test the function in local ? And could you please check if there is any error when execute test_func(myblob.name) ?Hury Shen
I removed test_func(myblb.name) function. still no luck. Not sure, how would I test this on local?Rameshwar Pawale
Run this command: func host start in your VS code Terminal window to start your function.Hury Shen
yes, changed account name to storage account name and deployed.Rameshwar Pawale
You do not need to re-deploy it to portal, you just need to change the My_STORAGE in application settings of your function app on portal. "local.settings.json" will not be deployed to azure portal when you do deployment.Hury Shen

2 Answers

1
votes

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}"

1
votes

I've had a similar problem. It was solved by adding the connection string as a key-value pair to the Application Settings in Function App->Configuration->Settings. I assume that it has to be done if Azure Functions Apps are deployed in a different storage container, for which there needs to be a different connection string.