[Python] Azure Function (python) won't trigger from Azure IoT Hub event

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

  1. Stack

    Stack Membro Participativo

    I have an IoT Hub and an Azure Function App written in Python. I want the Azure function to trigger on messages received by the hub.

    The IoT Hub is publicly accessible and I can successfully send messages to it. I have confirmed the JSON payloads are being received by using the Azure CLI.

    I've deployed the Azure function using VS Code (Azure extension) and the function.json looks like this:

    {
    "scriptFile": "__init__.py",
    "bindings": [
    {
    "type": "iotHubTrigger",
    "name": "event",
    "direction": "in",
    "eventHubName": "iothub-ehub-[redacted]-36471244-3e33dca112",
    "connection": "IoTHubConnectionString",
    "cardinality": "one",
    "consumerGroup": "mydevices"
    }
    ]
    }


    My python function (in __init__.py) starts with:

    def main(event: func.IoTHubEvent) -> None:
    ...


    In the Function App on the Azure Portal I have gone to Settings > Environmental Variables and set IoTHubConnectionString to Endpoint=sb://ihsuprodlnres017dednamespace.servicebus.windows.net/;SharedAccessKeyName=iothubowner;SharedAccessKey=[redacted];EntityPath=iothub-ehub-[redacted]-36471244-3e33dca112

    I've been struggling for a while now and I can't get the function to trigger, the Function App logs show nothing so I have no idea what's wrong.

    How can I troubleshoot this?

    Continue reading...

Compartilhe esta Página