pythonazureazure-functions

How to debug a zip deployment of a Python Azure Function?


I'm deploying a Python application as an Azure Functions App through a zip deployment. The project structure looks like this:

src/
├── lib
├── modules
    ├── __init__.py
    └── trivy/
        ├── __init__.py
        ├── fetch_release.py
        ├── send_notification.py
        ├── main.py
        └── adaptive_card_template.json
├── __init.py__
├── .funcignore
├── function_app.py
├── host.json
├── requirements.txt
└── local.settings.json
pyproject.toml
poetry.lock

where I only zip the src folder as it is the root of the Functions project.

The problem I am facing is that after running the following az command:

az functionapp deployment source config-zip --src ./dist/dependency-webhook-api.zip --resource-group ${AZURE_APP_RG} --name ${AZURE_APP_NAME} --subscription ${AZURE_APP_SUBSCRIPTION} --timeout 180

enter image description here The result indicates that the operation is a success, however the Function app does not display any functions on its GUI: enter image description here

| It has to be noted that I successfully ran the application locally using func start

These are the most important files:

function_app.py

# The function_app.py file is the main Azure functions initializer,
# here the app object gets created, and other functions,
# get registered to it.

import azure.functions as func

# Imports of azure functions from modules:
from modules.trivy.main import trivy_module

# Init the azure functions app
app = func.FunctionApp()

# Register azure functions from modules
app.register_functions(trivy_module)

host.json

{
  "version": "2.0",
  "logging": {
    "logLevel": {
      "default": "Warning",
      "Host.Aggregator": "Trace",
      "Host.Results": "Information",
      "Function": "Information"
    },
    "applicationInsights": {
      "samplingSettings": {
        "isEnabled": true,
        "excludedTypes": "Request"
      }
    }
  },
  "extensionBundle": {
    "id": "Microsoft.Azure.Functions.ExtensionBundle",
    "version": "[4.*, 5.0.0)"
  }
}

modules/trivy/main.py

import azure.functions as func
import logging

from lib.utils import ReleaseMode, newer_version_available

from .fetch_release import fetch_release_data
from .send_notification import send_notification

trivy_module = func.Blueprint()


@trivy_module.function_name(name="trivy_module")
@trivy_module.timer_trigger(
    schedule="0 12 * * 1", arg_name="timer", run_on_startup=True
)
def main(timer: func.TimerRequest):
    logging.info("Trivy module triggered.")
    response = fetch_release_data()
    logging.info("Trivy release data fetched.")
    if newer_version_available(ReleaseMode.MINOR_MODE, "v0.48.0", response["tag_name"]):
        send_notification(response)
        logging.info("Trivy notification update sent.")

EDIT: Added the requirements.txt:

azure-functions==1.20.0 ; python_version >= "3.11" and python_version < "4.0"
certifi==2024.7.4 ; python_version >= "3.11" and python_version < "4.0"
charset-normalizer==3.3.2 ; python_version >= "3.11" and python_version < "4.0"
idna==3.7 ; python_version >= "3.11" and python_version < "4.0"
requests==2.32.3 ; python_version >= "3.11" and python_version < "4.0"
urllib3==2.2.2 ; python_version >= "3.11" and python_version < "4.0"

If I run the az functionapp with the --build-remote true parameter, this is the output: enter image description here

If anyone has any idea how I can debug this deployment to see any error or why the application won't start as needed, your help would be much appreciated!


Solution

  • I have followed below steps and able to deploy the function code you have provided to Azure function app.

    npm i -g azure-functions-core-tools@4 --unsafe-perm true
    
    C:\Users\uname\Copy-of-azure-functions\src>func azure functionapp publish kpfn08
    Getting site publishing info...
    [2024-08-13T12:00:46.269Z] Starting the function app deployment...
    Removing WEBSITE_CONTENTAZUREFILECONNECTIONSTRING app setting.
    Removing WEBSITE_CONTENTSHARE app setting.
    Creating archive for current directory...
    Performing remote build for functions project.
    Uploading 12.52 KB [##############################################################################]
    Remote build in progress, please wait...
    Updating submodules.
    Preparing deployment for commit id 'de7a8d14-e'.
    PreDeployment: context.CleanOutputPath False
    PreDeployment: context.OutputPath /home/site/wwwroot
    Repository path is /tmp/zipdeploy/extracted
    Running oryx build...
    Command: oryx build /tmp/zipdeploy/extracted -o /home/site/wwwroot --platform python --platform-version 3.11 -p packagedir=.python_packages/lib/site-packages
    Operation performed by Microsoft Oryx, https://github.com/Microsoft/Oryx
    You can report issues at https://github.com/Microsoft/Oryx/issues
    
    Oryx Version: 0.2.20230210.1, Commit: a49c8f6b8abbe95bc884dea7fd0d86e, ReleaseTagName: 20230210.1
    
    //Removed few logs
    
    Number of duplicate files found 22
    Number of inodes 416
    Number of files 365
    Number of fragments 26
    Number of symbolic links  0
    Number of device nodes 0
    Number of fifo nodes 0
    Number of socket nodes 0
    Number of directories 51
    Number of ids (unique uids + gids) 1
    Number of uids 1
            root (0)
    Number of gids 1
            root (0)
    Creating placeholder blob for linux consumption function app...
    SCM_RUN_FROM_PACKAGE placeholder blob scm-latest-kpfn08.zip located
    Uploading built content /home/site/artifacts/functionappartifact.squashfs for linux consumption function app...
    Resetting all workers for kpfn08.azurewebsites.net
    Deployment successful. deployer = Push-Deployer deploymentPath = Functions App ZipDeploy. Extract zip. Remote build.
    Remote build succeeded!
    [2024-08-13T12:01:39.753Z] Syncing triggers...
    Functions in kpfn08:
        trivy_module - [timerTrigger]
    

    enter image description here