'Is it possible to run two functions (one running FastAPI - ASGI, and one running Flask - WSGI), in one Azure function App?
Im trying testing if its possible to run two functions in one Azure function app one running FastAPI and the other one running Flask.
I tried to specify a different route for each function.json file but to no avail.
# FastAPI function.json
{
"scriptFile": "__init__.py",
"bindings": [
{
"authLevel": "anonymous",
"type": "httpTrigger",
"direction": "in",
"name": "req",
"methods": [
"get",
"post",
"patch",
"delete"
],
"route": "/api/{*route}"
},
{
"type": "http",
"direction": "out",
"name": "$return"
}
]
}
# __init__.py
import logging
import azure.functions as func
from fastapi import FastAPI
app = FastAPI()
@app.get("/api/hello/")
async def hello():
return {'message': 'Hello World!'}
def main(req: func.HttpRequest, context: func.Context) -> func.HttpResponse:
return func.AsgiMiddleware(app).handle(req, context)
and
# Flask function.json
{
"scriptFile": "__init__.py",
"bindings": [
{
"authLevel": "anonymous",
"type": "httpTrigger",
"direction": "in",
"name": "req",
"methods": [
"get",
"post",
"patch",
"delete"
],
"route": "/flask/{*route}"
},
{
"type": "http",
"direction": "out",
"name": "$return"
}
]
}
#__init__.py
import logging
import azure.functions as func
from flask import Flask
app = Flask(__name__)
@app.route("/home/")
def home():
return "<p>Hello, World!</p>"
def main(req: func.HttpRequest, context: func.Context) -> func.HttpResponse:
return func.WsgiMiddleware(app.wsgi_app).handle(req, context)
Solution 1:[1]
If you deploy using GitHub, you can run two functions in one Azure function app.
- To do this push the required code in a GitHub repository.
- Then in the azure function go to the development center section.
- Then select source as GitHub it will ask you to login and for permissions.
- After granting them select the repository (the repository must be private) and then select branch then click save.
- Refresh the function app and you will see the triggers in the function section
refer the following documentation for further explaination
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | MohitGanorkar-MT |
