[Python] Python Azure Function not deploying due to missing modules

Discussão em 'Python' iniciado por Stack, Março 14, 2025.

  1. Stack

    Stack Membro Participativo

    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.com/en-us/a...guration#functions-not-found-after-deployment

    https://github.com/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.

    Continue reading...

Compartilhe esta Página