Create an Azure IoT Edge Environment

1.5 hours
  • 5 Learning Objectives

About this Hands-on Lab

Running cloud services on Edge devices can address a number of different challenges and scenarios, including intermittent internet connectivity, lower latency event architectures, and preprocessing data to reduce cloud storage and processing costs. In this lab, you will create an Azure IoT Edge environment on a Linux virtual machine to demonstrate how to deploy base Edge components. Then, you will configure and deploy 2 modules to your Edge device: a simulated temperature sensor and an Azure Stream Analytics job that will filter data generated by the sensor.

You will get the most from this lab if you are already familiar with Azure IoT Hub infrastructure and workflows.

Learning Objectives

Successfully complete this lab by achieving the following learning objectives:

Register Edge Device in Azure IoT Hub

From within the Azure portal:

  1. Navigate to the Azure IoT Hub already deployed into your lab subscription.
  2. Add an Edge device to the hub registry using symmetric key authentication; name it anything you like.
  3. Copy the Primary Connection String from the device registration and save it off for use in the next objective.
Deploy Azure IoT Edge Runtime to Linux VM and Connect to Hub

The VM you will use for your Edge device is already deployed into the lab subscription, and it also has required prerequisites for the Azure IoT Edge Runtime. The most notable prerequisite is a supported Ubuntu 18.04 OS and the Moby container runtime, which is required to run the Edge modules, all of which are deployed as Docker containers.

From within the Azure portal:

  1. Launch Cloud Shell choosing the Bash environment when prompted.
  2. When prompted to initialize storage for Cloud Shell, select Advanced settings, and add the storage account and file share. Note that the storage account name must be universally unique; you might want to use the random characters from the beginning of the resource group name as a part of your storage account name.

At the terminal command prompt:

  1. Use SSH to log in to your VM using the username, public IP, and password provided in the lab metadata. Answer in the affirmative to any questions; your response is case-sensitive. Your login will be in this form:
    ssh cloud_user@[labPublicIP] (ssh is lower-case).
  2. When prompted for the password, type or copy the password from the lab metadata. Note that the cursor will not move to show the number of characters or the password.
  3. Install the Azure IoT Edge runtime using this command:
    sudo apt-get install aziot-edge.
  4. If prompted, enter "Y" to continue.
  5. Create and populate a configuration file that will be used, in part, to connect to the Azure IoT Hub. In the command below, replace the placeholder value for the connection-string argument with the connection string you copied from the device registration:
    sudo iotedge config mp --connection-string 'PASTE_CNX_STRING'.
    Tip: Be sure your connection string is wrapped in single quotes.
  6. Verify that the config file was created and that it contains the connection string by viewing the file:
    sudo nano /etc/aziot/config.toml.
  7. CTRL-X to close the file and return to the command prompt.
  8. Apply the configuration to your runtime:
    sudo iotedge config apply -c '/etc/aziot/config.toml'.
  9. Check the status of the IoT Edge Runtime to ensure all is running or ready:
    sudo iotedge system status.
  10. Confirm that 1 of the 2 runtime modules, Edge Agent, is installed (you will install the other runtime module, Edge Hub, as a part of the other module deployments):
    sudo iotedge list.
  11. Minimize the terminal window. If it times out before you get back to use it, simply log back in using SSH.
  12. In the Azure portal, return to the device registration page, and scroll to find the modules section. You should see the Edge Agent running. Refresh as necessary. Don’t worry about any error-like messages you see in the IoT Edge Runtime Response property, slightly up the page from the modules section. That will clear up after the Edge Hub is deployed.
Configure Azure Stream Analytics Edge Job

In the Azure portal:

  1. Navigate to the skeletal Azure Stream Analytics job already set up for you. It is called ASAEdgeJob. You can see on the Overview page that this job does not yet have any inputs or outputs, and the query is just a placeholder.
  2. In the ASA job, create a stream input on Edge Hub with an alias of simTemperature.
  3. Create an output on Edge Hub (both the input and the output are on the Edge Hub runtime module, which acts as the broker). The alias for this output should be filteredTelemetry.
    Tip: Take note of the names of the ASA job and the input and the output aliases. You will need them in the next objective.
  4. The query acts as a transformation or filter over telemetry data that will be coming from the Simulated Temperature Module you will be deploying in the next objective. Alter the placeholder query so that it references the input and output aliases you just created.
  5. Set a filter on the temperature returned by the machine whenever the temperature is greater than 70.
    Hint: See the Additional Resources section of this lab for tips around how to query JSON messages and a sample message to help you build your query.
  6. Save the query.
  7. Associate the ASA job with the storage account already deployed with the lab.
    Tip: Make sure you select the account that was deployed with the lab, not the storage account you created to back your Cloud Shell. The save button will not be enabled if you select the Cloud Shell storage.
  8. Publish the job in order to stage it into a blob container for deployment in the next objective. This may take a few minutes. The system will set up a couple of containers in the storage account as a part of the staging process.
Configure Module and Routing Deployment Manifest
  1. Back in the IoT Edge device explorer, select your Edge device, and run the Set Modules wizard. This wizard builds a deployment manifest, which you will review before deploying the modules.
  2. Add the SimulatedTemperatureModule from the Marketplace.
  3. Add the Azure Stream Analytics module you staged in the the last objective. Note that the name of the module defaults to the same name as the job: ASAEdgeJob.
    UI Quirk: If the Save button is disabled, go back to the dropdown and explicitly select the job; the Save button should then be enabled.
  4. Change runtime settings, updating (or confirming) that the Image URI version for both Edge Agent and Edge Hub is 1.2. Do not alter any other values. This is required because the runtime you just installed is version 1.2.
  5. Continue to Routes and remove the default route named route (if it exists).
    Tip: To complete the next 2 steps, refer to the Additional Resources section of the lab to understand routing expression syntax.
  6. The SimulatedTemperatureSensorToIoTHub route was created by default when you added the module. This route sends all messages from the Simulated Temperature Module to the IoT Hub in the cloud, which is not what we want. Replace this route with one named SimulatedTempToASA and send all data from the simulated sensor to the Azure Stream Analytics module using the simTemperature input on the ASA module.
    Tip: You can rename and edit the route that was created or delete it and create a new route.
  7. Create a route that sends data from the ASA module, through the filteredTelemetry output, to the Azure IoT Hub in the cloud. Name the route FilteredDataToHub.
  8. Review the deployment manifest and go back to fix anything that doesn’t look right.
    Note: There may be a few places, particularly in route expressions, where characters, such as quotes, are escaped. That’s okay and expected.
  9. Deploy (Create) the modules.
Verify Running Edge Environment
  1. Back on the device details page, verify modules and their status in the same location as you did after installing the runtime on the VM.
    Note: Module deployment requires polling by the device, so this can take a few minutes. Refresh, as needed. Watch for the IoT Edge Runtime Response property to show a response code of "200 — OK" and refresh one more time if the modules still show errors.
  2. In the terminal window, log back in to the VM, if necessary, and run the same command you ran, previously, to see the list of modules. This time, instead of just the Edge Agent, you should see the Edge Hub, the SimulatedTemperatureSensor, and the ASAEdgeJob modules.
  3. Back on the IoT Hub overview page, you should also eventually see that messages are flowing to the hub.

Additional Resources

Imagine that you have recently been hired by Railtronics, a monitoring company that works with rail carriers to automate the monitoring and management of station equipment and facilities. They have decided to use Azure IoT to develop a solution that manages environmental temperature and humidity on sensors in both public areas as well as enclosed equipment housing.

Many of these rail stations serve agricultural locations that are close to the point of production but far from enterprise-grade internet connections. Connectivity can be spotty, which limits near-real-time data processing and event handling scenarios. This is a good scenario for Edge computing, but until each client invests in physical devices, you’ve been tasked with creating a repeatable process for setting up Azure IoT Edge environments on Linux virtual machines. This will allow teams to more quickly build the IoT solutions for Railtronics — and it will help you learn how to set up a base Azure IoT Edge environment.

Azure Stream Analytics Query Tips

When expressing the value of the temperature in the query, you do not need to cast it or round to a particular precision — simply 70 is fine.

Azure Stream Analytics (ASA) queries apply a subset of standard T-SQL syntax for doing streaming computations. When querying JSON messages in ASA, you refer to the object that contains the data of interest like this: <parentObject>.<child.object>

Below is a sample message from the SimulatedTemperatureSensor you will be deploying to your Edge device. If, in your query, you wanted to select the ambient temperature and humidity from the stream of messages, your SQL query would start with this SELECT clause:

SELECT ambient.temperature, ambient.humidity

Telemetry message example:

    "InstanceId": 1,
    "machine": {
        "temperature": 55.651076260675254,
        "pressure": 4.9475909664060413
    "ambient": {
        "temperature": 21.195752660602217,
        "humidity": 26
    "timeCreated": "2025-02-09T10:53:32.2731850+00:00"

Module Routing Expression Syntax

The basic structure of module routing expressions takes this form:

FROM [TheSourceOfData] [optionalCondition] INTO [TheDestinationOfData]

For basic routing expressions, the condition is optional or is simply "all data," which looks like this.

There are only a half-dozen ways to express the source and only 2 ways to express the sink or destination.

For this lab, you need to only know about these 2 source expressions after the FROM keyword.

  1. From a named module, using no or any output (moduleId is the name shown in the Set Module wizard):

  2. From a named module through a named output:


For the lab, you need to know about both destination or sink expressions after the INTO keyword.

  1. To the Azure IoT Hub in the cloud:

  2. To a specific module through a named output:


Read more about module routing syntax and module deployment manifests here: Learn how to deploy modules and establish routes in IoT Edge.

What are Hands-on Labs

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Sign In
Welcome Back!

Psst…this one if you’ve been moved to ACG!

Get Started
Who’s going to be learning?