aziotedge-modinit 1.0.7

dotnet tool install --global aziotedge-modinit --version 1.0.7
This package contains a .NET tool you can call from the shell/command line.
dotnet new tool-manifest # if you are setting up this repo
dotnet tool install --local aziotedge-modinit --version 1.0.7
This package contains a .NET tool you can call from the shell/command line.
#tool dotnet:?package=aziotedge-modinit&version=1.0.7
nuke :add-package aziotedge-modinit --version 1.0.7

Azure IoT Edge Module Initializer

dotnet tool to initialize Azure IoT Edge modules in Azure IoT Hub.

Installation

dotnet tool install -g aziotedge-modinit

requires donet sdk 6.0 or later

Usage

aziotedge-modinit --ConnectionStrings:IoTEdge="HostName=<HUB_ID>.azure-devices.net;DeviceId=<EDGEDEVICE_ID_>;SharedAccessKey=<EDGEDEVICE_SASKEY>" --moduleId="<$dgeHub|custom>"

⚠️ Warning ⚠️ When using $edgeHub or $edgeAgent in --moduleId make sure you escape the $ with \$ in bash or `$ in powershell.

TL;DR;

Azure IoT Hub creates Azure IoT Edge device identities, from the Azure Portal, Azure CLI, Azure PowerShell, or Azure IoT Hub REST API.

However, once created the system modules $edgeHub and $edgeAgent are not automatically initialized, and lack the connection string. Additionally, to create new module identities, you need to complete the SetModules workflow, which requires the connection string of the IoT Hub.

Both problems can be solved by using some hidden APIs that allow to initialize the system modules and create new modules without the need of the IoT Hub connection string, and using the Azure IoT edge connection string.

Quick Start

The following scripts create a new Azure IoT Edge device, initialize the system modules, and create a new module identity. Requires the az cli.

Set configuration variables

PowerShell:

$SUB_ID="<azure_sub>"
$HUB_ID="<hubname>"
$EDGE_ID="<edge_device>"

Bash

export SUB_ID=<azure_sub>
export HUB_ID=<hubname>
export EDGE_ID=<edge_device>

Create IoT Edge Device and System Modules

Powershell:

az account set -s $SUB_ID
az iot hub device-identity create -n $HUB_ID -d $EDGE_ID --edge-enabled
az iot edge set-modules -n $HUB_ID -d $EDGE_ID -k deploy.json

Bash

az account set -s $SUB_ID
az iot hub device-identity create -n $HUB_ID -d $EDGE_ID --edge-enabled
az iot edge set-modules -n $HUB_ID -d $EDGE_ID -k deploy.json

Initialize System Modules

Powershell:

$sasKey=(az iot hub device-identity show -n $HUB_ID -d $EDGE_ID --query authentication.symmetricKey.primaryKey -o tsv)
aziotedge-modinit --ConnectionStrings:IoTEdge="HostName=$HUB_ID.azure-devices.net;DeviceId=$EDGE_ID;SharedAccessKey=$sasKey" --moduleId="`$edgeHub"

Bash

sasKey=$(az iot hub device-identity show -n $HUB_ID -d $EDGE_ID --query authentication.symmetricKey.primaryKey -o tsv)
aziotedge-modinit --ConnectionStrings:IoTEdge="HostName=$HUB_ID.azure-devices.net;DeviceId=$EDGE_ID;SharedAccessKey=$sasKey" --moduleId="\$edgeHub"

Create new module

Bash/ Powershell:

aziotedge-modinit --ConnectionStrings:IoTEdge="HostName=$HUB_ID.azure-devices.net;DeviceId=$EDGE_ID;SharedAccessKey=$sasKey" --moduleId="myModule"
Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

This package has no dependencies.

Version Downloads Last updated
1.0.7 297 12/17/2023