Home > other >  What is a valid binding name for azure function?
What is a valid binding name for azure function?

Time:05-17

When I try to run the azure function defined below, I get the following error log

The 'my_function' function is in error: The binding name my_function_timer is invalid. Please assign a valid name to the binding.

What is the format of a valid binding name for Azure Function ?

Function definition

I have two files in my_function directory:

  • __init__.py contains the python code of the function
  • function.json contains the configuration of the function

Here is the content of those two files

__init__.py

import azure.functions as func
import logging

def main(my_function_timer: func.TimerRequest) -> None:
    logging.info("My function starts")
    print("hello world")
    logging.info("My function stops")

function.json

{
  "scriptFile": "__init__.py",
  "bindings": [
    {
      "name": "my_function_timer",
      "type": "timerTrigger",
      "direction": "in",
      "schedule": "0 0 1 * * *"
    }
  ]
}

I deploy this function using Azure/functions-action@v1 github action

CodePudding user response:

I didn't find anything on the documentation, but by looking at the source code of azure-functions-host, it uses following regex to validate the binding name.

^([a-zA-Z][a-zA-Z0-9]{0,127}|\$return)$

This means that a validate binding name must be either,

  • Alpha numeric characters(With at most 127)
  • Literal string $return

Since your binding name contains an _, the above regex does not match which will result in validation error.

CodePudding user response:

Please create the environment/folder structure

<project_root>/
 | - .venv/
 | - .vscode/
 | - my_first_function/
 | | - __init__.py
 | | - function.json
 | | - example.py
 | - my_second_function/
 | | - __init__.py
 | | - function.json
 | - shared_code/
 | | - __init__.py
 | | - my_first_helper_function.py
 | | - my_second_helper_function.py
 | - tests/
 | | - test_my_second_function.py
 | - .funcignore
 | - host.json
 | - local.settings.json
 | - requirements.txt
 | - Dockerfile

You can import modules in your function code using both absolute and relative references. Based on the folder structure shown above, the following imports work from within the function file <project_root>\my_first_function_init_.py:

from . import example #(relative)

The following app import and beyond top-level relative import are deprecated, since it is not supported by static type checker and not supported by Python test frameworks:

from app.shared_code import my_first_helper_function #(deprecated app import)

The function.json file defines the function's trigger, bindings, and other configuration settings. Every function has one and only one trigger. The runtime uses this config file to determine the events to monitor and how to pass data into and return data from a function execution. The following is an example function.json file.

{
    "disabled":false,
    "bindings":[
        // ... bindings here
        {
            "type": "bindingType",
            "direction": "in",
            "name": "myParamName",
            // ... more depending on binding
        }
    ]
}
  • Related