skip to Main Content

I’m trying to publish 2 functions to my Azure function app, "copy-read-from-esb".

Everything is written in Python in VS Code. The problem is that it looks like it will only register in my function app if the name of the Python file is function_app.py. But as I have 2, they cannot have the same name, and the one that is not called function_app.py will not register in my function app.

It looks like Azure functions use a function.json file, but I’m not certain how this works, nor if that only applies to C#.

I tried publishing through my CLI func azure functionapp publish .., and although this seems to work, I can only add one .py file because the required naming convention is somehow set to function__app.py.

2

Answers


  1. Chosen as BEST ANSWER

    Thank you, just to test quickly I added the function to the function_app.py:

    enter image description here

    enter image description here

    Looks like the both find the functionapp after publishing. But It seems they cant find the connectionstring, although referenced in the app settings.

    AzureWebJobsFeatureFlags is set to : EnableWorkerIndexing.


  2. You need to add both the Functions in the same function_app.py file or you can create a blueprint file and call all your Function triggers from there.

    Refer my SO answer1 to run 2 functions in function_app.py and SO answer2 for blueprint implemantation.

    enter image description here

    I created 2 functions and added them in function_app.py:-

    function_app.py:-

    import azure.functions as func
    import logging
    
    app = func.FunctionApp(http_auth_level=func.AuthLevel.ANONYMOUS)
    
    @app.route(route="http_trigger")
    def http_trigger(req: func.HttpRequest) -> func.HttpResponse:
        logging.info('Python HTTP trigger function processed a request.')
    
        name = req.params.get('name')
        if not name:
            try:
                req_body = req.get_json()
            except ValueError:
                pass
            else:
                name = req_body.get('name')
    
        if name:
            return func.HttpResponse(f"Hello, {name}. This HTTP triggered function executed successfully.")
        else:
            return func.HttpResponse(
                 "This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response.",
                 status_code=200
            )
    
    
    
    @app.timer_trigger(schedule="0 * * * * *", arg_name="myTimer", run_on_startup=True,
                  use_monitor=False) 
    def timer_trigger(myTimer: func.TimerRequest) -> None:
        
        if myTimer.past_due:
            logging.info('The timer is past due!')
    
        logging.info('Python timer trigger function executed.')
    

    Commands to deploy the Function via CLI:-

    az login
    az account set --subscription "SubscriptionName"
    func azure functionapp publish siliconfunc5
    

    Output:-

    Both the Function Triggers got deployed successfully with function core tools command above.

    enter image description here

    enter image description here

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