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
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:
But this does not install the packages in the correct location. Instead this command should be run:
Then the deployment is correct and the modules is installed properly.
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
:function_app.py
:OUTPUT
: