skip to Main Content

I am working on an Azure Function App where i have multiple Azure Functions defined as blueprints.

What i’m trying to do is create functions that the Azure Function blueprint can call inside the same file as the blueprint (refer to the example below).

BREAKS IN THE CLOUD:

import logging
import azure.functions as func

bp = func.Blueprint()


@bp.timer_trigger(
    schedule="0 0 10 * * *",
    arg_name="myTimer",
    run_on_startup=False,
    use_monitor=False,
)
def my_azure_function(myTimer: func.TimerRequest) -> None:
    do_something()

# This breaks the Function App in the cloud, not locally.
def do_something():
    logging.info("test log")

This works fine locally when i try and run it with the debugger, but when it is deployed to azure, the function does not show up under the Function App overview.

What is strange is removing the function and adding the code under the Azure Function blueprint itself does work when deployed (refer to the example below).

DOES NOT BREAK IN THE CLOUD:

import logging
import azure.functions as func

bp = func.Blueprint()


@bp.timer_trigger(
    schedule="0 0 10 * * *",
    arg_name="myTimer",
    run_on_startup=False,
    use_monitor=False,
)
def my_azure_function(myTimer: func.TimerRequest) -> None:
    # This was done by a function before
    logging.info("test log")

This is very annoying to me, as the Azure Function needs to do multiple things. Splitting the code up into multiple functions that can then be called by the Azure Function blueprint, is the best way to approach this i feel.

I have already done some research but was not able to find a solution to this issue. I have both looked through StackOverflow questions and read most of the Azure Function documentation.

Hope someone can tell me how to fix this or what i am doing wrong.

EDIT:

I have done some testing and found out it is when i import the "requests" module the functions disappear in the cloud. I wonder if there is some place i can see why?

2

Answers


  1. Chosen as BEST ANSWER

    I found out by looking through the documentation that the packages got installed wrong in the workflow generated by Azure.

    The workflow downloaded dependencies by running this command:

    pip install -r requirements.txt
    

    But this does not install the packages in the correct location. Instead this command should be run:

    pip install --target="./.python_packages/lib/site-packages" -r requirements.txt
    

    Then the deployment is correct and the modules is installed properly.


  2. but when it is deployed to azure, the function does not show up under the Function App overview.

    Blueprint cannot be deployed as Function to Azure Function.

    You need to import blueprint in the main file. In Azure Function is Recognized only when function is called using func.FunctionApp().

    For reference check this document.

    My Directory :

    blueprint.py:

    import azure.functions as func
    import logging
    
    bp = func.Blueprint()
    
    @bp.timer_trigger(arg_name="mytimer", schedule="0 */5 * * * *", run_on_startup=False, use_monitor=False)
    def my_azure_func(mytimer:func.TimerRequest):
        do_something()
    
    def do_something():
        logging.info("test log")
    

    function_app.py:

    import azure.functions as func
    import logging
    from blueprint import bp
    
    app= func.FunctionApp()
    
    app.register_functions(bp)
    

    OUTPUT:

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search