如何为多个 Azure Function 应用构建单个存储库

问题描述 投票:0回答:1

我是 Azure Functions 的新手,并且已成功部署了一个包含两个函数的函数应用程序。但是,我的要求发生了变化,我现在需要两个单独的功能应用程序,每个应用程序包含一个功能。

我正在努力了解如何构建项目以在单个存储库中容纳多个功能应用程序。我在 Azure 文档中没有找到有关此特定场景的太多有用信息。

以下是单功能和多功能应用程序的项目结构和配置。我正在寻找有关如何根据最佳实践最好地实施它的建议。

我成功部署了第二个场景,但是功能不起作用,所以我不知道是我忘记定义了什么还是路径错误。

1个功能App 2个功能 1 Function App 2 functions

function_app.py

import azure.functions as func
from function_app_blueprints.http_chatbot_industri import bp as http_chatbot_industri_bp
from function_app_blueprints.http_chatbot_babo import bp as http_chatbot_babo_bp

2 个具有单一功能的 Azure Function 应用程序

2 Azure Function Apps with single function in it

function_app_babo/function_app.py

import azure.functions as func
import logging
from src.chatbot_core.chatbot import Chatbot
from src.common.logging_utils import get_logger

app = func.FunctionApp(http_auth_level=func.AuthLevel.FUNCTION)
   

@app.function_name(name="fun_bamagpt_babo")

@app.route(route="ask_question")
def ask_question(req: func.HttpRequest) -> func.HttpResponse:
    logging.info('Python HTTP trigger function processed a request.')

    logger = get_logger(__name__)
    chatbot = Chatbot(logger)
    logging.info("Initilization completed...")

    # Get question
    req_body = {}
    question = req.params.get('question')
    if not question:
        try:
            req_body = req.get_json()
        except ValueError:
            pass
        else:
            question = req_body.get('question')
    
    logging.info(f'question: {question}')
    
    app = func.FunctionApp(http_auth_level=func.AuthLevel.FUNCTION)
    app.register_functions(http_chatbot_industri_bp)
app.register_functions(http_chatbot_babo_bp)
azure azure-functions cicd
1个回答
0
投票

正如我在评论中提到的

--prefix
不是
func azure functionapp publish
命令的有效选项。如本MS 文档中所示。

要使用此命令进行部署,您需要使用

cd
命令移动到每个功能应用程序目录并运行发布命令。

func azure functionapp publish <function-app-name>

我的目录:

functionapp1/function_app.py
:

import azure.functions as func
import datetime
import json
import logging

app = func.FunctionApp()

@app.route(route="http_trigger", auth_level=func.AuthLevel.ANONYMOUS)
def http_trigger(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 in functionapp1.")
    else:
        return func.HttpResponse(
             "This HTTP triggered function executed successfully in functionapp1. Pass a name in the query string or in the request body for a personalized response.",
             status_code=200
        )

OUTPUT

© www.soinside.com 2019 - 2024. All rights reserved.