Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Multiple ASGI functions with different names #1330

Closed
michael-wimmer-mw opened this issue Oct 19, 2023 · 4 comments
Closed

[Feature] Multiple ASGI functions with different names #1330

michael-wimmer-mw opened this issue Oct 19, 2023 · 4 comments
Assignees
Labels
feature feedback-needed Tracking the issue in order to gauge user interest or feedback. python

Comments

@michael-wimmer-mw
Copy link

michael-wimmer-mw commented Oct 19, 2023

We want to deploy multiple ASGI services (FastAPI) using this approach:
https://learn.microsoft.com/en-us/samples/azure-samples/fastapi-on-azure-functions/azure-functions-python-create-fastapi-app/
Currently, the functions are always called http_app_func.
That means that if we deploy one service it overwrites the one which was deployed previously.
Is there a way to customize the name of the function or any other possibility to have multiple ASGI services deployed in one function app?

Thanks in advance,
Michael

@michael-wimmer-mw michael-wimmer-mw changed the title Hi, Multiple ASGI functions with different names Oct 19, 2023
@yentini
Copy link

yentini commented Oct 23, 2023

The same happens to me. Furthermore, in Insights, functions cannot be distinguished as they all have the same name.

Captura

@YunchuWang YunchuWang self-assigned this Oct 24, 2023
@YunchuWang
Copy link
Member

@MichaelWimmerMaibornWolff, thanks for raising the issue. Unfortunately, it is not supported by our current python function runtime architecture, but we are working on new features that can resolve this problem. Will keep you updated.

@YunchuWang YunchuWang changed the title Multiple ASGI functions with different names [Feature] Multiple ASGI functions with different names Dec 20, 2023
@fredrike
Copy link

This works if you want multiple endpoints:

function_app.py

"""Main app"""

import azure.functions as func
from fastapi import FastAPI

fast_app_1 = FastAPI(root_path="/1")
fast_app_2 = FastAPI(root_path="/2")


@fast_app_1.get("/hello/{name}")
@fast_app_2.get("/hello/{name}")
async def get_name(name: str):
    return {
        "name": name,
    }


app = func.FunctionApp()


# Azure Functions v2 HTTP trigger decorator
@app.function_name("backend-api1")
@app.route(route="1/{*route}", auth_level=func.AuthLevel.ANONYMOUS)
async def backend_api(req: func.HttpRequest) -> func.HttpResponse:
    return await func.AsgiMiddleware(fast_app_1).handle_async(req)  # pragma: no cover


@app.function_name("backend-api2")
@app.route(route="2/{*route}", auth_level=func.AuthLevel.ANONYMOUS)
async def backend_api(req: func.HttpRequest) -> func.HttpResponse:
    return await func.AsgiMiddleware(fast_app_2).handle_async(req)  # pragma: no cover

host.json

{
  "version": "2.0",
  "extensions": {
    "http": {
      "routePrefix": ""
    }
  }
}

@vrdmr vrdmr assigned shreyabatra4 and unassigned YunchuWang Jun 27, 2024
@vrdmr vrdmr added feedback-needed Tracking the issue in order to gauge user interest or feedback. python labels Jun 27, 2024
@hallvictoria
Copy link
Contributor

This has been addressed in Azure/azure-functions-python-library#216 and will be available in the latest library version. AsgiFunctionApp and WsgiFunctionApp objects can now take in a customizable function_name param.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature feedback-needed Tracking the issue in order to gauge user interest or feedback. python
Projects
None yet
Development

No branches or pull requests

7 participants