Deploy a Module to Azure IOT Edge Runtime on Linux - Minified - 2
Tags: azure, linux, iot, devops
Published: 2020-03-18 12:50:09

After IOT Edge Hub and Runtime are set up, the next step is to deploy a Module to the Edge Device, and that's exactly what this tutorial is about!
The official documentation is very verbose and wordy, which is exactly how it should be, but this tutorial tries a more brief approach.

## Prerequisites

* You followed [Tutorial 1](https://dev.to/rohansawant/setup-azure-iot-edge-runtime-on-the-raspberry-pi-minified-8oa) where we [Setup Azure IOT Edge Portal and IOT Runtime on the Raspberry Pi](https://dev.to/rohansawant/setup-azure-iot-edge-runtime-on-the-raspberry-pi-minified-8oa)

  *OR*

* You have setup the Azure IOT Hub and the IOT Edge Runtime on a device

* You have verified that the Edge Device can talk to Azure


## You will learn 

1. How to deploy a Module onto the Edge Device from the Azure Portal
2. How to view the messages sent from the Edge Device to Azure

## Key Concepts

Modules - [Read More](https://docs.microsoft.com/en-us/azure/iot-edge/iot-edge-modules)

* modules are the smallest unit of computation managed by IoT Edge.

* can contain Azure services (such as Azure Stream Analytics) or your own solution-specific code.

* modules images exist as [container images](https://www.docker.com/resources/what-container) in a repository.

  

Working of the Deployment Process - [Read More](https://docs.microsoft.com/en-us/azure/iot-edge/module-composition)

1. You tell Azure what Module should be deployed to the Edge Device
2. Azure tells the Device about it via a configuration json file.
3. Device reads the json, and pulls the required Modules (container images) from a docker registry

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/rx024ygsqcjcho49t71h.png)


## Deploying a Module to IOT Edge Device

1) Sign in to the [Azure portal](https://portal.azure.com/) and navigate to your IoT hub from the left pane under **Automatic Device Management**, select **IoT Edge** and select the **Device** you want to deploy to.

2) On the upper bar, select **Set Modules**, then under **IoT Edge Modules**,  click **Add**. 

3) Select **Marketplace Module**, search for *"Simulated Temperature Sensor"*, select that, accept the defaults, next, review and create

  ![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/cnyhvrobyl0sjd6dlch0.png)

4) The Device periodically checks Azure for updates and it will automatically deploy the new Module, this might take about 5-10 minutes.

## Confirming that the Deploy worked.

1) Wait for the changes to propagate

2) On the terminal on your Edge Device to see list of deployed modules do, `sudo iotedge list`

3) Ensure that you see 3 modules deployed.

   ![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/te3egsvfmlo6a8g1uu7h.png)
References - [Deploy a Module - Quickstart: Deploy your first IoT Edge module to a virtual Linux device](https://docs.microsoft.com/en-us/azure/iot-edge/quickstart-linux#deploy-a-module)

## Viewing the Message on Azure IOT Hub

1) Open up the Azure Cli from Azure Portal, you should be already logged in.

2) Install the IOT Hub Extension 

   ```bash
   az extension add --name azure-cli-iot-ext
   ```

3) View the Logs sent by the Edge Device to Azure

   ```bash
   az iot hub monitor-events -n <NAME-OF-YOUR-HUB>
   ```

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/ogwaw56hc0pf6m7l0ed0.png)

That's it! You have successfully deployed your first Module from the Azure Portal, via the IOT Hub to the IOT Edge Device!


### Note

I know It's frustrating when something works in the tutorial but not when you do it, I would hate if that happened to you. So, please leave a comment, or reach out to me. If any of this does not work for you.