How to add our own module through java code and configure container create options also with java code

Madanala, Jayashree 151 Reputation points
2022-03-09T16:18:49.187+00:00

We have our own container(module) which we want to deploy into azure iot edge(under azure hub).
What Java SDK and Rest API we need to use to deploy our own container and what is sdk or apis we need to use to configure create options for IoT Edge modules.
Any sample code can you please share

I dont want to add new module through azure portal. I want to add modules from the java code with environment variables and create options everything from our code.

Please share the rest apis to use or sdk apis to use, any examples will help us.

Also how can i create secrets(username and password) for the modules in azure iot edge.

Azure IoT
Azure IoT
A category of Azure services for internet of things devices.
385 questions
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.
547 questions
Azure IoT SDK
Azure IoT SDK
An Azure software development kit that facilitates building applications that connect to Azure IoT services.
208 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Sander van de Velde 29,461 Reputation points MVP
    2022-03-09T18:00:50.94+00:00

    Hello @Madanala, Jayashree ,

    Do you want to deploy your own custom Azure IoT edge module written in Java?

    Please do some investigation first by creating this custom example module in Java.

    This will show you which libraries are needed and how to make use of the routing with input and output.

    From there you can either rework your existing code or migrate your code into the VS Code Azure IoT Edge module template.

    There are no Rest APIs involved on the edge. Yes, the IoT Hub and Device provisioning both have a rest API (next to eg. CLI) but this is for managing the resources, just like the functionality seen in the Azure portal.

    Deployment of modules under Azure IoT Edge (modules capable of connecting to the IoT Edge routing mechanism or generic containers like grafana or influxdb) is always done using the deployment manifest.

    In this deployment manifest, you can add container create options so you can configure eg. environment variables, ports, serial ports, volumes, etc. It's on par with what you see in Docker.

    Secrets could be added in the container create options (eg. as environment variables). But that is quite static (if these secrets change, you have to deploy the whole deployment manifest as an update). A common alternative is the use of Module Twin desired properties (each module has its own desired/reported properties, just like the device twin). These can be altered per module so it's perfect for custom modules.

    Again, put some time into learning the rich options of Azure IoT Edge.

    This MS Learn module is a nice starting point.

    0 comments No comments

  2. QuantumCache 20,031 Reputation points
    2022-03-10T01:08:30.807+00:00

    Hello @Madanala, Jayashree ,

    Welcome to this forum! Thanks for posting this query on using Azure IoTHub with Java stack! I hope the below info helps with your initial query!

    What Java SDK and Rest API we need to use to deploy our own container and what is sdk or apis we need to use to configure create options for IoT Edge modules.

    Below Are the Prerequisites:

    • A free or standard-tier IoT Hub in Azure.
    • A device running Azure IoT Edge with Linux containers. You can use the quickstarts to set up a Linux device or Windows device.
    • A container registry, like Azure Container Registry.
    • Visual Studio Code configured with the Azure IoT Tools.
    • Docker CE configured to run Linux containers.

    **To develop an IoT Edge module in Java, install the following additional prerequisites on your development machine:

    Java Extension Pack for Visual Studio Code.

    Java SE Development Kit 11, and set the JAVA_HOME environment variable to point to your JDK installation.

    Maven

    181662-image.png

    Any sample code can you please share
    Please share the rest apis to use or sdk apis to use, any examples will help us.

    We have great samples on Java stack: Please do explore over here: Samples

    I dont want to add new module through azure portal. I want to add modules from the java code with environment variables and create options everything from our code.

    Please follow this Github page: Microsoft Azure IoT SDKs for Java

    Also how can i create secrets(username and password) for the modules in azure iot edge.

    Correct me if you are referring to the Device Authentication methods: Please follow the below link for the documentation to choose your authentication method.
    Register device with IoT Hub
    181663-image.png

    You may post different questions\threads during your journey so that the community can help you quickly!

    Please comment in the below section for further help in this matter, happy to help.

    Please accept the helpful response as 'Answer', which will be helpful to others as well with similar questions