Azure function not getting blob trigger

83 Views Asked by At

I developed an Azure Function App using Python 3.9 around 2 to 3 years ago and deployed it using Visual Studio Code. The app consists of 3 functions: 2 blob triggers and 1 HTTP trigger. Initially, it was working fine, getting triggered whenever a file was uploaded to the specified container.

Recently, I needed to make some changes to the functions. While checking the functions, I found that in the monitor section of my function app, there were no logs for the last 30 days, even though new files had been entered into the specified container. Additionally, there were no logs for the HTTP triggered function. Upon further investigation, I realized that the function app has not been triggered for a few months. I haven't made any changes since the initial development. (My function app and storage account are in different resource groups.)

NTo fulfill my requirement, I created a new function app and deployed it with the old source code in the v1 format from my local machine using Visual Studio Code. However, while doing this, I encountered some errors.

Initially, after creating the function app and deploying it for the first time, the deployment was successful. However, upon uploading a file to the specified container, the function didn't get triggered.

Upon attempting a second deployment, I encountered the following error enter image description here

in log stream of function app i am getting this logs enter image description here

I have checked the connection string, which is specified correctly while deployment as application setting.

My host.json:

  "version": "2.0",
  "logging": {
    "applicationInsights": {
      "samplingSettings": {
        "isEnabled": true,
        "excludedTypes": "Request"
      }
    }
  },
  "extensionBundle": {
    "id": "Microsoft.Azure.Functions.ExtensionBundle",
    "version": "[2.*, 3.0.0)"
  }
}

Settings.json

{
  "azureFunctions.deploySubpath": ".",
  "azureFunctions.scmDoBuildDuringDeployment": true,
  "azureFunctions.pythonVenv": ".venv",
  "azureFunctions.projectLanguage": "Python",
  "azureFunctions.projectRuntime": "~4",
  "debug.internalConsoleOptions": "neverOpen"
}

tasks.json

{
  "version": "2.0.0",
  "tasks": [
    {
      "type": "func",
      "command": "host start",
      "problemMatcher": "$func-python-watch",
      "isBackground": true,
      "dependsOn": "pip install (functions)"
    },
    {
      "label": "pip install (functions)",
      "type": "shell",
      "osx": {
        "command": "${config:azureFunctions.pythonVenv}/bin/python -m pip install -r requirements.txt"
      },
      "windows": {
        "command": "${config:azureFunctions.pythonVenv}\\Scripts\\python -m pip install -r requirements.txt"
      },
      "linux": {
        "command": "${config:azureFunctions.pythonVenv}/bin/python -m pip install -r requirements.txt"
      },
      "problemMatcher": []
    }
  ]
}

Launch.json

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Attach to Python Functions",
      "type": "python",
      "request": "attach",
      "port": 9091,
      "preLaunchTask": "func: host start"
    }
  ]
}

extensions.json

{
  "recommendations": [
    "ms-azuretools.vscode-azurefunctions",
    "ms-python.python"
  ]
}

I attempted redeployment with the old function app, but encountered a different Oryx error. Consequently, I tried with another function app. My goal is to successfully deploy the function app and ensure that the blob trigger functions are activated upon file uploads.

1

There are 1 best solutions below

0
Vivek Vaibhav Shandilya On

You need to use latest Extension version in host.json file which is [4.*, 5.0.)

This worked for me:

I am using a sample blob trigger

#My Code :

__init__.py:

import logging

from azure.functions import InputStream


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

function.json:

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

launch.json:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Attach to Python Functions",
            "type": "python",
            "request": "attach",
            "port": 9091,
            "preLaunchTask": "func: host start"
        }
    ]
}

host.json:

{
  "version": "2.0",
  "logging": {
    "applicationInsights": {
      "samplingSettings": {
        "isEnabled": true,
        "excludedTypes": "Request"
      }
    }
  },
  "extensionBundle": {
    "id": "Microsoft.Azure.Functions.ExtensionBundle",
    "version": "[4.*, 5.0.0)"
  }
}

OUTPUT:

# Locally :

Functions:

        BlobTrigger1: blobTrigger

For detailed output, run func with --verbose flag.
[2024-02-20T12:18:03.432Z] Host lock lease acquired by instance ID '000000000000000000000000116B5F66'.
[2024-02-20T12:18:54.054Z] Executing 'Functions.BlobTrigger1' (Reason='New blob detected(LogsAndContainerScan): test/food_data.txt', Id=432b0cb7-f52e-4aa6-9b2f-e7549e5df026)
[2024-02-20T12:18:54.061Z] Trigger Details: MessageId: 49a19016-4323-424b-8854-3055e2f0bff5, DequeueCount: 1, InsertedOn: 2024-02-20T12:18:53.000+00:00, BlobCreated: 2024-02-20T12:18:52.000+00:00, BlobLastModified: 2024-02-20T12:18:52.000+00:00
[2024-02-20T12:18:54.241Z] Python blob trigger function processed blob 
Name: test/food_data.txt
Blob Size: None bytes
[2024-02-20T12:18:54.277Z] Executed 'Functions.BlobTrigger1' (Succeeded, Id=432b0cb7-f52e-4aa6-9b2f-e7549e5df026, Duration=375ms)

enter image description here

# Azure :

enter image description here

enter image description here

enter image description here

enter image description here