Read and Write to a file using iot edge custom Module

Satyam Chauhan 537 Reputation points
2022-10-04T10:01:45.903+00:00

Hi,

I have a requirement to read json data from a file in Iot edge custom module and after doing some processing I want to overwrite that file with new data.

I am using C# modules for custom modules and iot edge Runtime is installed in RHEL 8.

Locally I am able to run the module and it is working as expected, but after build and push it is throwing error -

Unhandled exception. System.AggregateException: One or more errors occurred. (Could not find file '/app/data.json'.)

Is there something that I am missing?

Azure IoT Edge
Azure IoT Edge
An Azure service that is used to deploy cloud workloads to run on internet of things (IoT) edge devices via standard containers.
548 questions
Azure IoT Hub
Azure IoT Hub
An Azure service that enables bidirectional communication between internet of things (IoT) devices and applications.
1,136 questions
0 comments No comments
{count} votes

Accepted answer
  1. Sander van de Velde 29,856 Reputation points MVP
    2022-10-04T21:32:20.73+00:00

    Hello @Satyam Chauhan ,

    As seen in the link @chbeier provided, you have to both add a binding to the container create options and provide filesystem access to the host folder.

    The module is sandboxed. It only sees a local folder structure (inside the module). You need to add a folder to the module which maps to a folder on the host filesystem.

    Check out the filesystem folders inside the container with:

    sudo docker exec -i -t echo /bin/bash

    See also this blob post with an example.

    2 people found this answer helpful.
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. chbeier 1,866 Reputation points
    2022-10-04T16:30:39.337+00:00

    Hi @Satyam Chauhan ,

    Have you checked the documentation on how to provide your module access to the device local storage for persistence? how-to-access-host-storage-from-module

    1 person found this answer helpful.
    0 comments No comments