[Python] GitHub Action - Deploy Python to Azure Function - import azure.identity not working

Discussão em 'Python' iniciado por Stack, Abril 8, 2025.

  1. Stack

    Stack Membro Participativo

    Problem I'm trying to deploy a Python Azure Function using GitHub Actions, but the deployment fails silently when my code includes azure-identity. The function works perfectly when deployed through VS Code, but not through GitHub Actions.

    Environment Python 3.11 Azure Functions (Consumption Plan) GitHub Actions for deployment

    Code: function_app.py:

    import azure.functions as func
    import logging
    from azure.identity import DefaultAzureCredential
    import json

    app = func.FunctionApp(http_auth_level=func.AuthLevel.FUNCTION)

    @app.route(route="fa_adtest_frontend_trigger")
    def fa_adtest_frontend_trigger(req: func.HttpRequest) -> func.HttpResponse:
    logging.info('Python HTTP trigger function processed a request.')
    # When this import is removed, deployment works fine
    credential = DefaultAzureCredential()
    # Rest of the function code


    Requirements.txt

    azure-functions
    azure-identity==1.15.0
    requests
    msal
    azure-core
    cryptography


    Github Actions Workflow:

    name: Deploy Python project to Azure Function App

    env:
    AZURE_FUNCTIONAPP_NAME: 'fa-apim-auth-frontend-001'
    AZURE_FUNCTIONAPP_PACKAGE_PATH: 'src/function-apps/frontend'
    PYTHON_VERSION: '3.11'

    jobs:
    deploy-function:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v4
    - uses: actions/setup-python@v4
    with:
    python-version: ${{ env.PYTHON_VERSION }}

    - name: 'Install Python Dependencies'
    working-directory: ${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }}
    run: |
    python -m pip install --upgrade pip wheel setuptools
    mkdir -p .python_packages/lib/site-packages
    pip install -r requirements.txt --target=".python_packages/lib/site-packages"

    - name: 'Deploy Function'
    uses: Azure/functions-action@v1
    with:
    app-name: ${{ env.AZURE_FUNCTIONAPP_NAME }}
    package: ${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }}
    scm-do-build-during-deployment: true


    Symptoms

    • Function deploys and works when azure-identity import is removed
    • When azure-identity is included, function doesn't appear in Azure portal after deployment
    • No explicit errors in GitHub Actions logs
    • Works fine when deployed through VS Code

    Continue reading...

Compartilhe esta Página