I'm trying to deploy a python azure function using a DevOps pipeline. For a while, the function would supposedly deploy correctly, but it wouldn't appear in the portal. Eventually I found I could get the function to deploy if I removed all non-native modules from the top of my function_app.py file. This leads me to assume the problem is that the python packages aren't getting built correctly.
This is the code in my pipeline to prep the package:
- job: PublishCode
steps:
- task: UsePythonVersion@0
displayName: 'Use Python 3.11'
inputs:
versionSpec: 3.11 # Functions V2 supports Python 3.6 as of today
architecture: 'x64'
- bash: |
pip install --target="./.python_packages/lib/site-packages" -r ./function_folder/requirements.txt
workingDirectory: $(workingDirectory)
- task: ArchiveFiles@2
displayName: 'Archive files'
inputs:
rootFolderOrFile: '$(workingDirectory)'
includeRootFolder: false
archiveType: zip
archiveFile: $(Build.ArtifactStagingDirectory)/package.zip
replaceExistingArchive: true
- publish: $(Build.ArtifactStagingDirectory)/package.zip
artifact: drop
The package is then deployed to the Azure function using a template my company has for Azure resource deployment, but the template uses the AzureFunctionApp@1 function, like so:
# Azure Deploy Function
- ${{ if eq(parameters.validateOnly, false) }}:
- task: AzureFunctionApp@1
condition: and(succeeded(), startsWith(variables['APP_TYPE'], 'functionApp'))
displayName: 'Azure Deploy Function'
inputs:
ConnectionType: 'AzureRM'
azureSubscription: ${{parameters.serviceConnection}}
appType: ${{parameters.appType}}
appName: ${{parameters.appName}}
${{ if ne('${{ parameters.slotName }}', '') }}:
SlotName: ${{parameters.slotName}}
deployToSlotOrASE: true
package: ${{parameters.package}}
ResourceGroupName: $(APP_RESOURCE_GROUP)
I should mention this is ran after terraform runs to create/update the function app as needed (also part of the template).
I've found in the Microsoft documentation the spot that talks about this exact problem, along with a github issue:
;tabs=vscode%2Cbash&pivots=python-mode-configuration#functions-not-found-after-deployment
Both say to download dependencies into ./.python_packages/lib/site-packages, but this doesn't work. I've also verified that my .zip file is correctly set up, and has the .python_package folder in it.
I'm trying to deploy a python azure function using a DevOps pipeline. For a while, the function would supposedly deploy correctly, but it wouldn't appear in the portal. Eventually I found I could get the function to deploy if I removed all non-native modules from the top of my function_app.py file. This leads me to assume the problem is that the python packages aren't getting built correctly.
This is the code in my pipeline to prep the package:
- job: PublishCode
steps:
- task: UsePythonVersion@0
displayName: 'Use Python 3.11'
inputs:
versionSpec: 3.11 # Functions V2 supports Python 3.6 as of today
architecture: 'x64'
- bash: |
pip install --target="./.python_packages/lib/site-packages" -r ./function_folder/requirements.txt
workingDirectory: $(workingDirectory)
- task: ArchiveFiles@2
displayName: 'Archive files'
inputs:
rootFolderOrFile: '$(workingDirectory)'
includeRootFolder: false
archiveType: zip
archiveFile: $(Build.ArtifactStagingDirectory)/package.zip
replaceExistingArchive: true
- publish: $(Build.ArtifactStagingDirectory)/package.zip
artifact: drop
The package is then deployed to the Azure function using a template my company has for Azure resource deployment, but the template uses the AzureFunctionApp@1 function, like so:
# Azure Deploy Function
- ${{ if eq(parameters.validateOnly, false) }}:
- task: AzureFunctionApp@1
condition: and(succeeded(), startsWith(variables['APP_TYPE'], 'functionApp'))
displayName: 'Azure Deploy Function'
inputs:
ConnectionType: 'AzureRM'
azureSubscription: ${{parameters.serviceConnection}}
appType: ${{parameters.appType}}
appName: ${{parameters.appName}}
${{ if ne('${{ parameters.slotName }}', '') }}:
SlotName: ${{parameters.slotName}}
deployToSlotOrASE: true
package: ${{parameters.package}}
ResourceGroupName: $(APP_RESOURCE_GROUP)
I should mention this is ran after terraform runs to create/update the function app as needed (also part of the template).
I've found in the Microsoft documentation the spot that talks about this exact problem, along with a github issue:
https://learn.microsoft/en-us/azure/azure-functions/recover-python-functions?source=recommendations&tabs=vscode%2Cbash&pivots=python-mode-configuration#functions-not-found-after-deployment
https://github/Azure/azure-functions-python-worker/issues/827
Both say to download dependencies into ./.python_packages/lib/site-packages, but this doesn't work. I've also verified that my .zip file is correctly set up, and has the .python_package folder in it.
Share Improve this question asked Mar 14 at 7:53 Ben HalladayBen Halladay 111 silver badge1 bronze badge 1 |1 Answer
Reset to default 1Actually, discovered the issue. I was using azure-identity, which currently has an issue with one of it's dependencies, Cryptography. I was able to fix the issue by putting an older version of cryptography (43.0.3) in my requirements.txt
This is the link to the github issue:
https://github/Azure/azure-sdk-for-python/issues/38725
In case something happens to the link, here's the answer from one of the cryptography devs explaining what happened:
---------------------------------------------------------------------------
Hi folks, I'm one of the pyca/cryptography developers
SCM_DO_BUILD_DURING_DEPLOYMENT=true
and ensurePYTHONPATH=./.python_packages/lib/site-packages
in the function app settings. – Dasari Kamali Commented Mar 14 at 10:09