Hello @Matías Liñán García Greetings! Welcome to Microsoft Q&A forum. Thank you for posting your question here.
The first function you have provided in the question works on HttpTrigger
. The HTTP trigger lets you invoke a function with an HTTP request. Whereas the second function sample you have provided is configured with EventGridTrigger
. This is used to respond to an event sent by an Event Grid source. You must have an event subscription to the source to receive events and the function gets triggered only when an event is received on the Event grid source. Please refer the resource Azure Functions triggers and bindings concepts to get more details on the Trigger options available for Azure function and how they can be used.
I understand the you are trying to follow the tutorial Ingest IoT Hub telemetry into Azure Digital Twins. Please note that the Azure function defined in this article relies on an Event Grid which is supposed to receive data from Azure IoT Hub. The binding of Azure function with the Event Grid can be made using the step outlined in the section Connect the function to IoT Hub. Here is the CLI command for your reference.
az eventgrid event-subscription create --name <name-for-hub-event-subscription> --event-delivery-schema eventgridschema --source-resource-id /subscriptions/<your-subscription-ID>/resourceGroups/<your-resource-group>/providers/Microsoft.Devices/IotHubs/<your-IoT-hub> --included-event-types Microsoft.Devices.DeviceTelemetry --endpoint-type azurefunction --endpoint /subscriptions/<your-subscription-ID>/resourceGroups/<your-resource-group>/providers/Microsoft.Web/sites/<your-function-app>/functions/IoTHubtoTwins
Once you have the Event Grid bound to Azure function and have a client that sends data to Event Grid (IoT Hub device telemetry sample in the given tutorial), you should be able to see the function getting triggered.
Please ensure that you have done all the configurations mentioned in the article and assigned appropriate permissions to the Azure function app to access Azure Digital Twin instance in order to update the Digital Twin.
Hope this helps. Please let us know if you have any additional questions or need further assistance. We would be glad to help you.
If the response helped, please do click Accept Answer and Yes . Doing so would help other community members with similar issue identify the solution. I highly appreciate your contribution to the community.