Azure blob input binding without trigger

Haris Papageorge 251 Reputation points
2022-06-20T09:56:59.323+00:00

Hi,

I have a working function that triggers every time a message arrives in my IoTHUB.

I am also successfully sending a blob to a storage container I created. That blob is a block blob.

I would like to combine the two and and use that blob value inside my function.

I read this but I am really confused as to how I should go about doing this inside the portal since I am not using the trigger that is described in the tutorial. What should I include in the function.json inside the portal and is that the only change I have to do? What should I use for the path and connection attributes?

Here's my function.json file:

{
"bindings": [
{
"type": "eventHubTrigger",
"name": "events",
"direction": "in",
"eventHubName": "samples-workitems",
"cardinality": "many",
"connection": "thermos_events_IOTHUB",
"consumerGroup": "$Default"
}
]
}

thanks

Azure Blob Storage
Azure Blob Storage
An Azure service that stores unstructured data in the cloud as blobs.
Azure IoT Hub
Azure IoT Hub
An Azure service that enables bidirectional communication between internet of things (IoT) devices and applications.
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Sander van de Velde | MVP 36,951 Reputation points MVP Volunteer Moderator
    2022-06-22T13:45:23.707+00:00

    Hello @Haris Papageorge ,

    you want to send incoming Azure IoT Hub device messages to a blob in Azure Storage.

    there are several ways to do this without an Azure Function:

    • You can make use of an IoT Hub route and send (filtered) messages to a blob storage endpoint.
    • If you send/route messages to an EventHub, you can make use of the Archive option of that Event Hub.

    Still, working with an Azure Function is helpful if you want to execute custom logic.

    Notice, use a custom consumer group like 'fa' to prevent two services from reading the same IoT Hub messages (that will lead to errors):

    213894-image.png

    You can add custom consumer groups in the IoT Hub using the 'Built-in endpoints' menu option.

    In the Function, triggered by an incoming IoT Hub message, just add a Blob storage output:

    213906-image.png

    This should look like this:

    213895-image.png

    Check out this output example too.


  2. Sander van de Velde | MVP 36,951 Reputation points MVP Volunteer Moderator
    2022-07-15T15:01:36.75+00:00

    Hello @Haris Papageorge ,

    I finally found some time to dig into this question.

    You want to have an Azure Function, triggered by an IoT Hub message and join the message data with data coming from a file set in a blob storage container.

    This is possible by adding an input binding for Azure Storage.

    I have created this sample C# project in GitHub which shows how to combine this. This is an Azure Function project, best opened in Visual Studio:

    221191-image.png

    As you can see, a file named 'data.txt' is read from a container named 'blobfilecontainer'. I use a static value to prevent reading the file every time an IoT Hub message arrives.

    If you want to debug this project locally, you need to provide a file named local.settings.json:

    221128-image.png

    I added this example file, just rename it.

    The 'BlobStorageConnectionString' and 'EventHubConfigConnectionString' must be added to the application settings (not in the connection strings section) of the configuration of the actual Azure Function.

    I tested this with the Raspberry Pi Azure IoT Online Simulator. This is the console output:

    221118-image.png

    Perhaps a similar function can be established using the portal editor but I recommend working with this Azure Function template for more control. Debugging is possible on your development device and you can check-in the code (version control).

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.