0

function.json

{
    "scriptFile": "__init__.py",
    "disabled": false,
    "bindings": [
        {
            "name": "blob",
            "type": "blobTrigger",
            "direction": "in",
            "path": "{CONTAINERNAME}",
            "connectionStringSetting": "BLOB_CONNECTION_STRING"
        }
    ]
}

app/init.py

CONTAINERNAME =os.environ.get("CONTAINERNAME")
def main(blob: func.InputStream):
    logging.info(f"Python blob trigger function processed blob \n"
                 f"Name:{blob.name}\n"
                 f"Blob Size: {blob.length} bytes")

I am required to pass the dynamic container name to function.json as it may change/update in the future so somehow I can pass it through the environment variable. I have tried different ways like

  • %CONTAINERNAME%
  • ${CONTAINERNAME}
  • {CONTAINERNAME}
  • "pathStringSetting": "{CONTAINERNAME}",

But I'm getting the same error: The 'app' function is in error: Unable to configure binding 'blob' of type 'blobTrigger'. This may indicate invalid function.json properties. Can't figure out which ctor to call.

1 Answer 1

0

I passed the dynamic container name to function.json as %CONTAINERNAME%/{name} and successfully executed the blob trigger function.

Code :

import os
import logging
import azure.functions as func

CONTAINERNAME = os.environ.get("CONTAINERNAME")

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

function.json :

{
  "scriptFile": "__init__.py",
  "bindings": [
    {
      "name": "blob",
      "type": "blobTrigger",
      "direction": "in",
      "path": "%CONTAINERNAME%/{name}",
      "connection": "kamblobfuncstr_STORAGE"
    }
  ]
}

local.settings.json :

{
  "IsEncrypted": false,
  "Values": {
    "AzureWebJobsStorage": "<storage_connec_string>",
    "FUNCTIONS_WORKER_RUNTIME": "python",
    "kamblobfuncstr_STORAGE": "<storage_connec_string>",
    "CONTAINERNAME": "<containe_name>"
  }
}

Output :

The following blob trigger function code successfully triggered the blob as shown below:

 *  Executing task: .venv\Scripts\activate && func host start 

Found Python version 3.10.11 (py).

Azure Functions Core Tools
Core Tools Version:       4.0.5030 Commit hash: N/A  (64-bit)
Function Runtime Version: 4.15.2.20177

Functions:

        BlobTrigger1: blobTrigger

For detailed output, run func with --verbose flag.
[2024-03-13T06:49:09.828Z] Worker process started and initialized.
[2024-03-13T06:49:23.397Z] Host lock lease acquired by instance ID '00000000xxxxxxxxxxx'.
[2024-03-13T06:49:35.791Z] Executing 'Functions.BlobTrigger1' (Reason='New blob detected(LogsAndContainerScan): samples-workitems/samplekam.txt', Id=143133a3-c1e5xxxxxxxxxxxxx)
[2024-03-13T06:49:35.797Z] Trigger Details: MessageId: dd61e79axxxxxxxxxx, DequeueCount: 1, InsertedOn: 2024-03-13T06:49:34.000+00:00, BlobCreated: 2024-03-13T06:49:27.000+00:00, BlobLastModified: 2024-03-13T06:49:27.000+00:00
[2024-03-13T06:49:35.887Z] Python blob trigger function processed blob
Name:samples-workitems/samplekam.txt
Blob Size: None bytes
[2024-03-13T06:49:35.911Z] Executed 'Functions.BlobTrigger1' (Succeeded, Id=1431xxxxxxxxxxxxxx, Duration=907ms)

enter image description here

Azure Portal :

Below is the blob I sent to the samples-workitems container.

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

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.