pythonazurevisual-studio-codeazure-functionstimer-trigger

Python Azure Time Trigger Function not showing in Azure Portal after successful deployment from VS code


I have a Time Trigger Function written in Python 3.11.9 in Visual Studio code. The function runs successfully locally (using F5). When I deploy the function to the Azure portal from Visual Studio Code, it shows as "Deployment successful." in both the Output and Azure tab

enter image description here

enter image description here

However, when I go to my Function App on Azure Portal, the App files show in the function section enter image description here

but my time trigger function does not shows in the overview section of the function app in the Azure Portal enter image description here

When deploying from VS Code, I tried deploying from;

  1. the Local Workspace section on the Azure tab enter image description here

  2. The Resource section on Azure tab

enter image description here

  1. Through terminal

enter image description here

(which gives a slightly different output, see below)

enter image description here

But none of these methods were able to fix the problem of the Azure Function not showing up on my Azure Portal Function App.

here is the function code with imports(function_app.py)

import logging
import azure.functions as func
import requests
import json
from simple_salesforce import Salesforce
import pandas as pd
import csv
from flatten_json import flatten
#for extending csv file for 1 day at a time holidays
import datetime as dt
from datetime import timedelta
from urllib.parse import urlparse, urljoin
#used to save to specific folder 
import os
from dotenv import load_dotenv
from shareplum import Site
from shareplum import Office365
from shareplum.site import Version
from io import BytesIO
from io import StringIO
import pandas as pd
from office365.runtime.auth.authentication_context import AuthenticationContext
from io import BytesIO 
from office365.runtime.auth.client_credential import ClientCredential 
from office365.sharepoint.client_context import ClientContext
#sharepoint
# import necessary modules
from shareplum import Site
import pandas as pd
from shareplum import Office365
from shareplum import Site
from shareplum.site import Version
import pandas as pd
import numpy as np
from sklearn.datasets import load_iris
from IPython.display import display
from tabulate import tabulate
from pandas import json_normalize
from office365.sharepoint.files.file import File
import pandas as pd
import io
import errno
from datetime import datetime, timedelta
from pathlib import Path
from azure.identity import DefaultAzureCredential
from azure.keyvault.secrets import SecretClient
from azure.core.exceptions import ResourceNotFoundError
from azure.storage.blob import BlobServiceClient
from azure.identity import DefaultAzureCredential
from azure.keyvault.keys import KeyClient

app = func.FunctionApp()

@app.schedule(schedule="0 */5 * * * *", arg_name="myTimer", run_on_startup=True,
              use_monitor=False) 
def timer_trigger(myTimer: func.TimerRequest) -> None:
    if myTimer.past_due:
        logging.info('The timer is past due!')

    logging.info('Python timer trigger function executed.')


    #full script below this, inline with function so it runs when the function runs 

The modules used (requirements.txt file)

flatten-json==0.1.14 
ipython==8.12.3 
numpy==1.26.4 
Office365-REST-Python-Client==2.5.7 
pandas==2.2.0 
python-dotenv==1.0.1 
requests==2.31.0 
scikit-learn==1.4.2 
SharePlum==0.5.1 
simple-salesforce==1.12.5 
tabulate==0.9.0

local.settings.json file ( I have tried using "UseDevelopmentStorage=true" and not using this, both gave the same result of no function being present on Azure Portal)

{
  "IsEncrypted": false,
  "Values": {
    "AzureWebJobsStorage": "",
    "FUNCTIONS_WORKER_RUNTIME": "python",
    "AzureWebJobsFeatureFlags": "EnableWorkerIndexing"
  }
}

FIXED : adding the additional requirements from Ikhtesam's answer below fixed this issue

FUNCTION FAILING TO EXECUTE WITHIN PORTAL

My function is now showing in the portal and attempting to run every 5 mins (as intended) but failing to execute on each run enter image description here

below is the Invocation Traces enter image description here And Invocation Traces Description enter image description here

Running the Query in Application Insights enter image description here

Logs Message: enter image description here

Method of retrieving KeyVault Values:

keyVaultName = "<key-vault-name>"
KVUri = f"https://{keyVaultName}.vault.azure.net"

credential = DefaultAzureCredential()
client = SecretClient(vault_url=KVUri, credential=credential)

username = client.get_secret("username").value
password = client.get_secret("password").value
security_token = client.get_secret("security-token").value
domain = client.get_secret("domain").value

Key Vault Reference : enter image description here

Configuration Section : enter image description here

enter image description here

Access Policies blocked due to RBAC enter image description here Access Configuration enter image description here

These are the roles I currently have

enter image description here

-UPDATE

The enterprise/function/service app role: enter image description here

Access Denied : enter image description here


Solution

  • Please add all the modules in the requirements.txt file. I have added following modules in requirements.txt which are used in function_app.py.

    azure-functions
    requests
    simple-salesforce
    pandas
    flatten-json
    python-dotenv
    SharePlum
    Office365-REST-Python-Client
    numpy
    ipython
    scikit-learn
    tabulate
    azure-identity
    azure-keyvault
    azure-core
    azure-storage-blob
    

    I have same code alike you in function_app.py file.

    enter image description here

    enter image description here

    enter image description here

    Update-

    To get the secret value from key vault in the function app, perform the following steps-

    1. Enable Managed Identity in function app.

    enter image description here

    1. Copy the Object(Principal) Id from above and add it in Access policies of your key vault instance in order to grant permission to your function app.

    enter image description here

    enter image description here

    Click Next -> Review + create

    enter image description here

    Once it is created, you will get the expected response.