In order to deploy multiple functions at once you need to execute func init --worker-runtime python --model V2
command once which will create all the default files needed for a function. Then you can run func new
command many times if you would like to add different trigger functions in it.
If you will run func new
thrice for creating one HTTP triggered function and 2 timer trigger function then the folder structure and function_app.py
would look like below-
Folder Structure-
![enter image description here](https://cdn.statically.io/img/i.imgur.com/Zg8TMhn.png)
function_app.py-
import azure.functions as func
import datetime
import json
import logging
app = func.FunctionApp()
@app.timer_trigger(schedule="0 */5 * * * *", arg_name="myTimer", run_on_startup=True,
use_monitor=False)
def TimerTriggerFunction(myTimer: func.TimerRequest) -> None:
if myTimer.past_due:
logging.info('The timer is past due!')
logging.info('Python timer trigger function executed.')
@app.route(route="HttpTriggeredFunction", auth_level=func.AuthLevel.ANONYMOUS)
def HttpTriggeredFunction(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 0 0/1 * * *", arg_name="myTimer", run_on_startup=True,
use_monitor=False)
def TimerTriggeredFunction2(myTimer: func.TimerRequest) -> None:
if myTimer.past_due:
logging.info('The timer is past due!')
logging.info('Python timer trigger function executed.')
You can either deploy using func azure functionapp publish <function_APP_Name>
command or vs code.
![enter image description here](https://cdn.statically.io/img/i.imgur.com/Ct2WCP5.png)
![enter image description here](https://cdn.statically.io/img/i.imgur.com/ASpCHpF.png)
![enter image description here](https://cdn.statically.io/img/i.imgur.com/by3YAFS.png)
Portal-
![enter image description here](https://cdn.statically.io/img/i.imgur.com/9ileT76.png)
func azure functionapp publish <App Name>
command will publish the local function to an existing function app.func azure functionapp...