我正在尝试部署Azure Function执行简单计算。它部署成功,因为我可以看到 * 您的Functions 4.0应用程序已启动并运行 *。我的逻辑(inspired by this)设置如下。
import azure.functions as func
app = func.FunctionApp(http_auth_level=func.AuthLevel.ANONYMOUS)
@app.route(route="addition")
def main(req: func.HttpRequest) -> str:
a = req.params.get("a")
b = req.params.get("b")
return "{}".format(int(a) * int(b))
当我导航到/api/addition?a=2&b=3
时,我没有看到预期的结果。404找不到
我试过使用VS Code Azure Function extension进行部署。这是成功的,我可以在屏幕上确认预期的结果。但是我不想用VS Code。我错过了什么?谷歌搜索它是具有挑战性的,因为每个人都问如何在VS代码中做到这一点。
buildpipe的编译大致如下。
- task: UsePythonVersion@0
inputs:
versionSpec: $(pythonVersion)
disableDownloadFromRegistry: true
addToPath: true
architecture: 'x64'
displayName: 'Use python $(pythonVersion)'
- script: |
python -m venv antenv
source antenv/bin/activate
pip install -r requirements.txt
workingDirectory: $(projectRoot)
displayName: 'Install requirements'
- task: ArchiveFiles@2
inputs:
rootFolderOrFile: '$(projectRoot)'
includeRootFolder: false
archiveType: 'zip'
archiveFile: '$(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip'
replaceExistingArchive: true
- publish: '$(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip'
artifact: drop
然后,它像这样展开。
- task: UsePythonVersion@0
inputs:
versionSpec: $(pythonVersion)
disableDownloadFromRegistry: true
addToPath: true
architecture: 'x64'
displayName: 'Use python $(pythonVersion)'
- task: AzureFunctionApp@2
inputs:
azureSubscription: $(azureSubscription)
appType: 'functionAppLinux'
appName: 'func-calculationtest'
package: '$(Pipeline.Workspace)/drop/$(Build.BuildId).zip'
runtimeStack: 'PYTHON|3.10'
deploymentMethod: 'auto'
1条答案
按热度按时间of1yzvn41#
我用你的代码创建了一个Azure Functions PythonV 2 Http触发器,它可以做简单的加法,将代码推送到Azure存储库,并通过Azure DevOps将其部署到Function应用程序,如下所示:
Yaml code:-
输出:-