Store and Analyze IoT Data
Learn On Demand
Learn On Demand Pro Series

1 hour

This IT Pro Challenge hands-on lab shows learners how to use the Azure Portal to configure a web app to use an Azure Internet of Things (IoT) Hub that has three device registrations, create two connection strings, provision a function app, and use a test web application to verify the function app configuration.

Become one of the 3 million IT and Cyber professionals advancing their careers

Sign up with

Already have an account? Sign In »


In this IT Pro Challenge, learners will understand how to configure an Azure Internet of Things (IoT) Hub as a datasource that has three device registrations and two connection strings. Learners will also provision a function app with a custom function that is triggered by IoT Hub events and creates a document in a Cosmos DB, use a web app to emulate and test the registered IoT devices, and use Azure Time Series Insights to analyze the data collected. The skills learned in this lab are beneficial for careers as a network or system administrator.


The scenario for this hands-on lab is that you are a system administrator, and your company is deploying an Internet of Things (IoT) data solution. Your job is to route IoT streaming data to a Cosmos DB database that uses the SQL API and use Azure Time Series Insights to generate analytical data. To do this, you need to add a Cosmos DB account as an output and generate a document for each device. You will also provision a Time Series Insights resource, configure the Azure IoT Hub as a data source, and analyze IoT data that the Hub receives.

Configure a web app to use an Azure IoT Hub

To begin the lab, you need to sign into the Azure portal and define device registrations (Building001, Vehicle002, and Device003) in the provided Azure IoT Hub. Next, you will add a Connection string (iotHubConnectionString) to the Application Settings page of the provided web app and set the value of the string to the iothubowner connection string for the Azure IoT Hub. Then you will add another Connection string (eventHubConnectionString) to the Event hub-compatible endpoint for the Azure IoT Hub.

Provision a function app

Now you will provision a function app (iotfun12608288) that uses the provided Storage account. Add a custom function (iotxfer) to the funcion app that is triggered by the Azure IoT Hub events. Then, open the Integration page for the iotxfer function and set the Event parameter name (deviceReading). Add a Cosmos DB output that links to the collection you just created in a new database (iot) in the Cosmos DB account. Next, you will modify the code for the iotxfer function that creates a document in the Cosmos DB for each event captured. An example of the function code is:

#r "Newtonsoft.Json" using System; using Newtonsoft.Json; using Newtonsoft.Json.Linq; public static void Run(string deviceReading, out object outputDocument, TraceWriter log) { dynamic reading = JObject.Parse(deviceReading); outputDocument = new { deviceid = reading.DeviceID, time = reading.Time, reading = reading.Reading }; log.Info($"Processed a reading for {reading.DeviceID} from {reading.Time}"); }

As proof of concept, you will use the provided web app to test your configuration. The test page emulates the IoT device interactions. You will select Emulate Devices to test the three IoT devices that you added.

Analyze data with Azure Time Series Insights

Finally, you will provision an Azure Time Series Insights environment (tsi12608288). Then you will add an IoT Hub Event Source (iot) and analyze the Reading data, export a JSON file with a sample of the source events, and upload the JSON file to a new container (analysis) in the provided Storage Account.

Summary Conclusion

By taking this hands-on lab, you will learn how to provision a function app that is triggered by Azure IoT Hub events, configure a Cosmos DB account output for the function app, route data from an Azure IoT Hub to a Cosmos DB account, and analyze the IoT data using Azure Time Series Insights.