Hello Aditi Mokashi,
Welcome to the Microsoft Q&A and thank you for posting your questions here.
I understand that you would like to create multiple functions withing a single Azure function app service.
Yes. It is absolutely possible to deploy multiple HTTP-triggered functions within a single Azure Function App, and make each accessible through distinct endpoints. I will provide you an extensive tested steps and best practices, you can successfully deploy multiple HTTP-triggered functions within a single Function App while ensuring efficient management and scalability.
NOTE:
- If Cost Efficiency Is a Priority stick to a single function app with the outlined setup. Monitor resource utilization to avoid bottlenecks.
- If Scalability or Advanced Features Are Needed use API Management or separate function apps for more control and scalability.
To Implement Multiple HTTP Triggers
- Begin by creating a Function App in the Azure portal. Select "Create a resource" and choose "Function App." Specify your subscription, resource group, and app name. Ensure the runtime stack is Python 3.9, the operating system is Linux, and the hosting plan is set to P1v3. This configuration supports scalability and aligns with your requirements.
- On your local machine, install Azure Functions Core Tools and the Azure Functions extension for Visual Studio Code. These tools simplify project creation and deployment.
- In Visual Studio Code, initialize a new Azure Functions project. Add two HTTP-triggered functions,
automation1
andautomation2
, and organize them into separate directories as shown:
my-function-app/
├── automation1/
│ ├── __init__.py
│ ├── function.json
├── automation2/
│ ├── __init__.py
│ ├── function.json
├── host.json
├── local.settings.json
This will help you to create Functions with unique endpoints.
- Write the business logic for each function in its respective
__init__.py
file:
- automation1/init.py:
import logging
import azure.functions as func
def main(req: func.HttpRequest) -> func.HttpResponse:
logging.info('Processing request for automation1.')
return func.HttpResponse("Hello from automation1!", status_code=200)
- automation2/init.py:
import logging
import azure.functions as func
def main(req: func.HttpRequest) -> func.HttpResponse:
logging.info('Processing request for automation2.')
return func.HttpResponse("Hello from automation2!", status_code=200)
- Define HTTP trigger bindings in the
function.json
files to set up unique routes for each function:-
automation1/function.json
:
-
{
"bindings": [
{
"authLevel": "function",
"type": "httpTrigger",
"direction": "in",
"name": "req",
"methods": ["get", "post"],
"route": "automation1"
},
{
"type": "http",
"direction": "out",
"name": "res"
}
]
}
```
- `automation2/function.json`:
```json
{
"bindings": [
{
"authLevel": "function",
"type": "httpTrigger",
"direction": "in",
"name": "req",
"methods": ["get", "post"],
"route": "automation2"
},
{
"type": "http",
"direction": "out",
"name": "res"
}
]
}
- Then, at this stage using Visual Studio Code to deploy the project to Azure. Right-click the project and choose Deploy to Function App. This action publishes your functions to the cloud, where they can be accessed through
api/automation1
andapi/automation2
.
Alternative Approaches
- If advanced features such as centralized management, rate limiting, or caching are required, integrate Azure API Management. You can configure
automation1
andautomation2
as backend APIs, exposing them through consistent endpoints like/api/v1/automation1
. - For scenarios requiring isolated scaling or deployment, consider creating separate Function Apps for each HTTP trigger. This approach improves resource allocation and fault isolation but may increase administrative overhead.
To ensure best practices:
Use a Premium or Dedicated Plan to mitigate cold start delays and handle high traffic efficiently to - Optimize Resource Allocation.
Apply appropriate authorization levels (function
, admin
, or anonymous
) to protect your endpoints.
Integrate Azure Application Insights to track performance metrics and debug issues for each function individually.
Then, use function-specific error handling and retries to ensure that a failure in one function does not disrupt others.
If you will need to read more details about the above solution, use the below references:
- https://learn.microsoft.com/en-us/azure/azure-functions/functions-bindings-http-webhook-trigger
- https://learn.microsoft.com/en-us/azure/azure-functions/functions-create-serverless-api
- https://learn.microsoft.com/en-us/azure/api-management/api-management-key-concepts
I hope this is helpful! Do not hesitate to let me know if you have any other questions.
Please don't forget to close up the thread here by upvoting and accept it as an answer if it is helpful.