[Python] How to connect Azure Function App with Event Grid

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

  1. Stack

    Stack Membro Participativo

    I'm trying to connect an Azure Function app, the premium one, that have the code uploaded in a docker image, that is uplod to the container registry. When I try to make a subscription in the Event Grid Topic, and connect it to the Function App, I condigue the endpoint to the Function App, and the function that I want to trigger, but doesn't arrive to the function app. It gives me this error: "message": "outcome=NotFound

    This is my Dockerfile for the function app:

    FROM mcr.microsoft.com/azure-functions/python:4-python3.11
    ENV AzureWebJobsScriptRoot=/home/site/wwwroot \
    AzureFunctionsJobHost__Logging__Console__IsEnabled=true

    COPY ./src /home/site/wwwroot
    COPY ./requirements.txt /home/site/wwwroot
    COPY ./requirements_function_app.txt /home/site/wwwroot

    RUN apt-get update
    RUN apt-get install -y chromium chromium-driver
    RUN apt-get clean
    RUN rm -rf /var/lib/apt/lists/*

    WORKDIR /home/site/wwwroot

    RUN mkdir /home/site/wwwroot/process_url
    RUN mv /home/site/wwwroot/azure_functions/process_url.py /home/site/wwwroot/process_url/process_url.py
    RUN mv /home/site/wwwroot/azure_functions/function_process_url.json /home/site/wwwroot/process_url/function.json
    RUN mkdir /home/site/wwwroot/delete_url
    RUN mv /home/site/wwwroot/azure_functions/delete_url.py /home/site/wwwroot/delete_url/delete_url.py
    RUN mv /home/site/wwwroot/azure_functions/function_delete_url.json /home/site/wwwroot/delete_url/function.json

    RUN ls

    RUN pip install --no-cache-dir -r requirements.txt
    RUN pip install --no-cache-dir -r requirements_function_app.txt


    And this is my azure function app:

    import azure.functions as func
    import logging
    import json
    from dotenv import load_dotenv
    load_dotenv()

    from utils.executor_functions import process_urls

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

    LOGGER = logging.getLogger()
    LOGGER.setLevel(logging.DEBUG)

    @app.function_name(name="process_url")
    @app.event_grid_trigger(arg_name="azeventgrid")
    async def process_url_fa(azeventgrid: func.EventGridEvent) -> func.HttpResponse:
    logging.info('Python HTTP trigger function processed a request.')


    And this the JSON:

    {
    "scriptFile": "process_url.py",
    "bindings": [
    {
    "authLevel": "anonymous",
    "type": "eventGridTrigger",
    "direction": "in",
    "name": "process_url"
    },
    {
    "type": "http",
    "direction": "out",
    "name": "$return"
    }
    ]
    }


    I tried with the eventgrid endpoint that appears in Azure Portal, in the EventGrid resource

    Any ideas to try?

    I tried to connect it via webHook and with the function app url but doesn't work. I don't know where is the problem.

    Continue reading...

Compartilhe esta Página