Skip to content

Contact sales

By filling out this form and clicking submit, you acknowledge our privacy policy.
  • Labs icon Lab
  • A Cloud Guru
Azure icon
Labs

Create an Azure IoT Edge Environment

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.

Azure icon
Labs

Path Info

Level
Clock icon Intermediate
Duration
Clock icon 1h 30m
Published
Clock icon Feb 25, 2022

Contact sales

By filling out this form and clicking submit, you acknowledge our privacy policy.

Table of Contents

  1. Challenge

    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.
  2. Challenge

    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.
  3. Challenge

    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.
  4. Challenge

    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.
  5. Challenge

    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.

The Cloud Content team comprises subject matter experts hyper focused on services offered by the leading cloud vendors (AWS, GCP, and Azure), as well as cloud-related technologies such as Linux and DevOps. The team is thrilled to share their knowledge to help you build modern tech solutions from the ground up, secure and optimize your environments, and so much more!

What's a lab?

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.

Provided environment for hands-on practice

We will provide the credentials and environment necessary for you to practice right within your browser.

Guided walkthrough

Follow along with the author’s guided walkthrough and build something new in your provided environment!

Did you know?

On average, you retain 75% more of your learning if you get time for practice.

Start learning by doing today

View Plans