Create multiple functions in one Azure Function App
Question:
I want to create multiple python Azure Functions within one Azure Functions App using the azure cli/core tools. One http triggered function and one blob triggered function.
I have the following folder structure:
├── azure-functions
│ ├── az-func-blob
│ │ ├── .python_packages
│ │ ├── .vscode
│ │ ├── .gitignore
│ │ ├── function_app.py
│ │ ├── host.json
│ │ ├── local_settings.json
│ │ ├── requirements.txt
│ ├── az-func-http
│ │ ├── .python_packages
│ │ ├── .vscode
│ │ ├── .gitignore
│ │ ├── function_app.py
│ │ ├── host.json
│ │ ├── local_settings.json
│ │ ├── requirements.txt
│ ├── README.md
Note: I created the individual function directories with the following commands within my project dir "azure-functions":
-
Blob function:
func init az-func-blob --worker-runtime python --model V2
cd az-func-blob
func new --template "Blob trigger" --name BlobTrigger
-
Http function:
func init az-func-http --worker-runtime python --model V2
cd az-func-http
func new --template "HTTP trigger" --name HTTPTrigger
If I navigate to the directory of one of these functions and run the command func azure functionapp publish SPIEFUNC2
it works fine. However running this command again in the other function directory will overwrite the Trigger/Function in Azure instead of appending a new one even though the trigger names are different.
Apparently that’s just how it works in Azure but I don’t know how to create multiple functions within one Function app.
I saw this post here where someone suggested to use the same "host.json" for all functions. I don’t know how to do this as every host.json is exactly the same anyway and looks like this:
{
"version": "2.0",
"logging": {
"applicationInsights": {
"samplingSettings": {
"isEnabled": true,
"excludedTypes": "Request"
}
}
},
"extensionBundle": {
"id": "Microsoft.Azure.Functions.ExtensionBundle",
"version": "[4.*, 5.0.0)"
}
}
Can someone please explain in detail how to get set this up using only one Azure Function App instead of multiple function apps?
Answers:
Can someone please explain in detail how to get set this up using only one Azure Function App instead of multiple function apps?
I am able to deploy multiple functions to a Function App using func azure functionapp publish <function_APP_Name>
command.
Thanks @Thomas for the comment, you need to run func init --worker-runtime python --model V2
command once and func new
twice.
- I have created one Http Triggered Function and Blob Triggered Function as shown below-
- When you will run
func init --worker-runtime python --model V2
, all the default files will get created for a function. Upon running func new
, it will add the triggers in it.
I have deployed the functions to the function app and got successful deployed output.
I am able to see the functions in the function app.
Output–
I want to create multiple python Azure Functions within one Azure Functions App using the azure cli/core tools. One http triggered function and one blob triggered function.
I have the following folder structure:
├── azure-functions
│ ├── az-func-blob
│ │ ├── .python_packages
│ │ ├── .vscode
│ │ ├── .gitignore
│ │ ├── function_app.py
│ │ ├── host.json
│ │ ├── local_settings.json
│ │ ├── requirements.txt
│ ├── az-func-http
│ │ ├── .python_packages
│ │ ├── .vscode
│ │ ├── .gitignore
│ │ ├── function_app.py
│ │ ├── host.json
│ │ ├── local_settings.json
│ │ ├── requirements.txt
│ ├── README.md
Note: I created the individual function directories with the following commands within my project dir "azure-functions":
-
Blob function:
func init az-func-blob --worker-runtime python --model V2
cd az-func-blob
func new --template "Blob trigger" --name BlobTrigger
-
Http function:
func init az-func-http --worker-runtime python --model V2
cd az-func-http
func new --template "HTTP trigger" --name HTTPTrigger
If I navigate to the directory of one of these functions and run the command func azure functionapp publish SPIEFUNC2
it works fine. However running this command again in the other function directory will overwrite the Trigger/Function in Azure instead of appending a new one even though the trigger names are different.
Apparently that’s just how it works in Azure but I don’t know how to create multiple functions within one Function app.
I saw this post here where someone suggested to use the same "host.json" for all functions. I don’t know how to do this as every host.json is exactly the same anyway and looks like this:
{
"version": "2.0",
"logging": {
"applicationInsights": {
"samplingSettings": {
"isEnabled": true,
"excludedTypes": "Request"
}
}
},
"extensionBundle": {
"id": "Microsoft.Azure.Functions.ExtensionBundle",
"version": "[4.*, 5.0.0)"
}
}
Can someone please explain in detail how to get set this up using only one Azure Function App instead of multiple function apps?
Can someone please explain in detail how to get set this up using only one Azure Function App instead of multiple function apps?
I am able to deploy multiple functions to a Function App using func azure functionapp publish <function_APP_Name>
command.
Thanks @Thomas for the comment, you need to run func init --worker-runtime python --model V2
command once and func new
twice.
- I have created one Http Triggered Function and Blob Triggered Function as shown below-
- When you will run
func init --worker-runtime python --model V2
, all the default files will get created for a function. Upon runningfunc new
, it will add the triggers in it.
I have deployed the functions to the function app and got successful deployed output.
I am able to see the functions in the function app.
Output–