I have an Azure Function based on Python 3.12 (same issue when I downgrade to Python 3.11). This worked fine until I imported azure.identity
and azure.keyvault.secrets
. Since I've added them the functions are not shown anymore in my Azure Function. When I remove them the functions will be back. It is fine when the package is loaded from the requirements.txt
. The issue just happens when I add
from azure.keyvault.secrets import SecretClient
from azure.identity import DefaultAzureCredential
What can be the issue what leads to that?
Project Structure
function_app.py
import azure.functions as func
from http_blueprint import bp_http
from timer_blueprint import bp_timer
app = func.FunctionApp()
app.register_functions(bp_http)
app.register_functions(bp_timer)
http_blueprint.py
import logging
import azure.functions as func
bp_http = func.Blueprint()
@bp_http.route(route="default_template")
def default_template(req: func.HttpRequest) -> func.HttpResponse:
...
timer_blueprint.py
import os
import requests
import logging
import datetime
import azure.functions as func
from azure.keyvault.secrets import SecretClient
from azure.identity import DefaultAzureCredential
#same issue when libaries would be imported like this
#import azure.identity
#import azure.keyvault.secrets
bp_timer = func.Blueprint()
@bp_timer.timer_trigger(schedule="0 * * * * *",
arg_name="mytimer",
run_on_startup=True)
def exec_timer(mytimer: func.TimerRequest) -> None:
...
azure_pipelines.yml (based on the sample; build and deploy at the moment back to back - will be splitted if everything works)
pool:
vmImage: ubuntu-latest
strategy:
matrix:
Python312:
python.version: '3.12'
steps:
- task: UsePythonVersion@0
inputs:
versionSpec: '$(python.version)'
displayName: 'Use Python $(python.version)'
- script: |
python -m pip install -U pip
python -m pip install --target="./.python_packages/lib/site-packages" --upgrade -r requirements.txt
displayName: 'Install dependencies'
- task: ArchiveFiles@2
displayName: 'Archive files'
inputs:
rootFolderOrFile: $(System.DefaultWorkingDirectory)
includeRootFolder: false
archiveType: zip
archiveFile: $(Build.ArtifactStagingDirectory)/$(Build.BuildId)-$(python.version).zip
replaceExistingArchive: true
- task: PublishBuildArtifacts@1
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)'
ArtifactName: 'drop'
publishLocation: 'Container'
- task: AzureFunctionApp@2
inputs:
connectedServiceNameARM: 'Deploy'
appType: 'functionAppLinux'
appName: 'appName'
package: '$(Build.ArtifactStagingDirectory)/$(Build.BuildId)-$(python.version).zip'
runtimeStack: 'PYTHON|3.12'
deploymentMethod: 'zipDeploy'
requirements.txt
azure-functions==1.21.3
discord.py==2.5.2
discord_interactions==0.4.0
Flask==3.1.0
requests==2.32.3
azure-identity==1.21.0
azure-keyvault-secrets==4.9.0
cryptography==43.0.3
The issue could be related to version incompatibility between azure-identity
, azure-keyvault-secrets
, and the function app you are deploying to.
Follow below steps:
requirements.txt
to avoid indirect conflicts between packages.requirements.txt:
azure-functions
discord.py
discord_interactions
Flask
requests
azure-identity
azure-keyvault-secrets
cryptography
I have tested by deploying your code to Azure function app with Python version 3.11
(Consumption Plan) with few modifications.
http_blueprint.py:
import logging
import azure.functions as func
bp_http = func.Blueprint()
@bp_http.route(route="default_template")
def default_template(req: func.HttpRequest) -> func.HttpResponse:
do_something()
return func.HttpResponse(f" This HTTP triggered function executed successfully.")
def do_something():
logging.info("http test log")
timer_blueprint.py:
import datetime
import logging
import os
import azure.functions as func
import requests
from azure.identity import DefaultAzureCredential
from azure.keyvault.secrets import SecretClient
bp_timer = func.Blueprint()
@bp_timer.timer_trigger(schedule="0 * * * * *",
arg_name="mytimer",
run_on_startup=True)
def exec_timer(mytimer: func.TimerRequest) -> None:
do_something()
def do_something():
logging.info("timer test log")
local.settings.json:
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"FUNCTIONS_WORKER_RUNTIME": "python",
"AzureWebJobsFeatureFlags": "EnableWorkerIndexing"
}
}
Deployed the function to Azure function app with Python version 3.11.
Creating placeholder blob for linux consumption function app...
SCM_RUN_FROM_PACKAGE placeholder blob scm-latest-kpfn7.zip located
Uploading built content /home/site/artifacts/functionappartifact.squashfs for linux consumption function app...
Resetting all workers for kpfn7.azurewebsites.net
Deployment successful. deployer = Push-Deployer deploymentPath = Functions App ZipDeploy. Extract zip. Remote build.
Remote build succeeded!
[2025-04-07T05:52:51.797Z] Syncing triggers...
Functions in kpfn7:
default_template - [httpTrigger]
Invoke url: https://kpfn7.azurewebsites.net/api/default_template
exec_timer - [timerTrigger]
default_template - httptrigger:
2025-04-07T06:55:02Z [Information] Executing 'Functions.default_template' (Reason='This function was programmatically called via the host APIs.', Id=c81f33d3-7f94-4627-8f4f-474171e5ec20)
2025-04-07T06:55:02Z [Verbose] Sending invocation id: 'c81f33d3-7f94-4627-8f4f-474171e5ec20
2025-04-07T06:55:02Z [Verbose] Posting invocation id:c81f33d3-7f94-4627-8f4f-474171e5ec20 on workerId:c81a3721-85a3-4a38-a15b-f14b6e31d37a
2025-04-07T06:55:02Z [Information] http test log
2025-04-07T06:55:02Z [Information] Executed 'Functions.default_template' (Succeeded, Id=c81f33d3-7f94-4627-8f4f-474171e5ec20, Duration=8ms)
exec_timer - timerTrigger: