You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/iot-edge/tutorial-deploy-function.md
+23-27Lines changed: 23 additions & 27 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,7 @@ description: In this tutorial, you develop an Azure Function as an IoT Edge modu
4
4
author: PatAltimore
5
5
6
6
ms.author: patricka
7
-
ms.date: 05/11/2022
7
+
ms.date: 3/22/2023
8
8
ms.topic: tutorial
9
9
ms.service: iot-edge
10
10
services: iot-edge
@@ -33,16 +33,16 @@ The Azure Function that you create in this tutorial filters the temperature data
33
33
34
34
## Prerequisites
35
35
36
-
Before beginning this tutorial, you should have gone through the previous tutorial to set up your development environment for Linux container development: [Develop IoT Edge modules using Linux containers](tutorial-develop-for-linux.md). By completing that tutorial, you should have the following prerequisites in place:
36
+
Before beginning this tutorial, do the tutorial to set up your development environment for Linux container development: [Develop IoT Edge modules using Linux containers](tutorial-develop-for-linux.md). After completing that tutorial, you should have the following prerequisites in place:
37
37
38
38
* A free or standard-tier [IoT Hub](../iot-hub/iot-hub-create-through-portal.md) in Azure.
39
-
* An AMD64 device running Azure IoT Edge with Linux containers. You can use the quickstarts to set up a [Linux device](quickstart-linux.md) or [Windows device](quickstart.md).
39
+
* An AMD64 device running Azure IoT Edge with Linux containers. You can use the quickstart to set up a [Linux device](quickstart-linux.md) or [Windows device](quickstart.md).
40
40
* A container registry, like [Azure Container Registry](../container-registry/index.yml).
41
41
*[Visual Studio Code](https://code.visualstudio.com/) configured with the [Azure IoT Edge](https://marketplace.visualstudio.com/items?itemName=vsciot-vscode.azure-iot-edge) and
* Download and install a [Docker compatible container management system](support.md#container-engines) on your development machine. Configure it to run Linux containers.
44
44
45
-
To develop an IoT Edge module in with Azure Functions, install the following additional prerequisites on your development machine:
45
+
To develop an IoT Edge module with Azure Functions, install additional prerequisites on your development machine:
46
46
47
47
*[C# for Visual Studio Code (powered by OmniSharp) extension](https://marketplace.visualstudio.com/items?itemName=ms-dotnettools.csharp).
@@ -53,32 +53,30 @@ The Azure IoT Edge for Visual Studio Code that you installed in the prerequisite
53
53
54
54
### Create a new project
55
55
56
-
Create a C# Function solution template that you can customize with your own code.
56
+
Follow these steps to create a C# Function solution template that's customizable.
57
57
58
58
1. Open Visual Studio Code on your development machine.
59
59
60
60
2. Open the Visual Studio Code command palette by selecting **View** > **Command Palette**.
61
61
62
-
3. In the command palette, enter and run the command **Azure IoT Edge: New IoT Edge solution**. Follow the prompts in the command palette to create your solution.
62
+
3. In the command palette, add and run the command **Azure IoT Edge: New IoT Edge solution**. Follow these prompts in the command palette to create your solution:
63
63
64
-
| Field | Value |
65
-
| ----- | ----- |
66
-
| Select folder | Choose the location on your development machine for Visual Studio Code to create the solution files. |
67
-
| Provide a solution name | Enter a descriptive name for your solution, like **FunctionSolution**, or accept the default. |
| Provide a module name | Name your module **CSharpFunction**. |
70
-
| Provide Docker image repository for the module | An image repository includes the name of your container registry and the name of your container image. Your container image is prepopulated from the last step. Replace **localhost:5000** with the **Login server** value from your Azure container registry. You can retrieve the Login server from the Overview page of your container registry in the Azure portal. The final string looks like \<registry name\>.azurecr.io/CSharpFunction. |
64
+
* Select a folder: choose the location on your development machine for Visual Studio Code to create the solution files.
65
+
* Provide a solution name: add a descriptive name for your solution, like **FunctionSolution**, or accept the default.|
66
+
* Select a module template: choose **Azure Functions - C#**.
67
+
* Provide a module name | Name your module **CSharpFunction**.
68
+
* Provide a Docker image repository for the module. An image repository includes the name of your container registry and the name of your container image. Your container image is pre-populated from the last step. Replace **localhost:5000** with the **Login server** value from your Azure container registry. You can retrieve the **Login server** from the **Overview** page of your container registry in the Azure portal. The final string looks like \<registry name\>.azurecr.io/csharpfunction.
71
69
72
-
:::image type="content" source="./media/tutorial-deploy-function/repository.png" alt-text="Screenshot showing where to choose your Docker image repository in Visual Studio Code.":::
70
+
:::image type="content" source="./media/tutorial-deploy-function/repository.png" alt-text="Screenshot showing where to add your Docker image repository name in Visual Studio Code.":::
73
71
74
72
### Add your registry credentials
75
73
76
-
The environment file stores the credentials for your container registry and shares them with the IoT Edge runtime. The runtime needs these credentials to pull your private images onto the IoT Edge device.
74
+
The environment file of your solution stores the credentials for your container registry and shares them with the IoT Edge runtime. The runtime needs these credentials to pull your private images onto your IoT Edge device.
77
75
78
-
The IoT Edge extension tries to pull your container registry credentials from Azure and populate them in the environment file. Check to see if your credentials are already included. If not, add them now:
76
+
The IoT Edge extension in Visual Studio Code tries to pull your container registry credentials from Azure and populate them in the environment file. Check to see if your credentials are already in the file. If not, add them now:
79
77
80
-
1. In the Visual Studio Code explorer, open the .env file.
81
-
2. Update the fields with the **username** and **password** values that you copied from your Azure container registry.
78
+
1. In the Visual Studio Code explorer, open the `.env` file.
79
+
2. Update the fields with the **username** and **password** values that you copied from your Azure container registry. You can find them again by going to your container registry in Azure and looking on the **Settings** > **Access keys** page.
82
80
3. Save this file.
83
81
84
82
>[!NOTE]
@@ -88,15 +86,15 @@ The IoT Edge extension tries to pull your container registry credentials from Az
88
86
89
87
Running Azure Functions modules on IoT Edge is supported only on Linux AMD64 based containers. The default target architecture for Visual Studio Code is Linux AMD64, but we will set it explicitly to Linux AMD64 here.
90
88
91
-
1. Open the command palette and search for **Azure IoT Edge: Set Default Target Platform for Edge Solution**, or select the shortcut icon in the side bar at the bottom of the window.
89
+
1. Open the command palette and search for **Azure IoT Edge: Set Default Target Platform for Edge Solution**.
92
90
93
91
2. In the command palette, select the AMD64 target architecture from the list of options.
94
92
95
93
### Update the module with custom code
96
94
97
-
Let's add some additional code so that the module processes the messages at the edge before forwarding them to IoT Hub.
95
+
Let's add some additional code so your **CSharpFunction** module processes the messages at the edge before forwarding them to IoT Hub.
98
96
99
-
1. In Visual Studio Code, open **modules** > **CSharpFunction** > **CSharpFunction.cs**.
97
+
1. In the Visual Studio Code explorer, open **modules** > **CSharpFunction** > **CSharpFunction.cs**.
100
98
101
99
1. Replace the contents of the **CSharpFunction.cs** file with the following code. This code receives telemetry about ambient and machine temperature, and only forwards the message on to IoT Hub if the machine temperature is above a defined threshold.
102
100
@@ -198,13 +196,13 @@ In the previous section, you created an IoT Edge solution and modified the **CSh
198
196
Visual Studio Code outputs a success message when your container image is pushed to your container registry. If you want to confirm the successful operation for yourself, you can view the image in the registry.
199
197
200
198
1. In the Azure portal, browse to your Azure container registry.
201
-
2. Select **Repositories**.
199
+
2. Select **Services** > **Repositories**.
202
200
3. You should see the **csharpfunction** repository in the list. Select this repository to see more details.
203
201
4. In the **Tags** section, you should see the **0.0.1-amd64** tag. This tag indicates the version and platform of the image that you built. These values are set in the module.json file in the CSharpFunction folder.
204
202
205
203
## Deploy and run the solution
206
204
207
-
You can use the Azure portal to deploy your Function module to an IoT Edge device like you did in the quickstarts. You can also deploy and monitor modules from within Visual Studio Code. The following sections use the Azure IoT Edge and IoT Hub for Visual Studio Code that was listed in the prerequisites. Install the extension now, if you didn't already.
205
+
You can use the Azure portal to deploy your Function module to an IoT Edge device like you did in the quickstart. You can also deploy and monitor modules from within Visual Studio Code. The following sections use the Azure IoT Edge and IoT Hub for Visual Studio Code that was listed in the prerequisites. Install the extensions now, if you haven't already.
208
206
209
207
1. In the Visual Studio Code explorer, under the **Azure IoT Hub** section, expand **Devices** to see your list of IoT devices.
210
208
@@ -220,11 +218,9 @@ You can use the Azure portal to deploy your Function module to an IoT Edge devic
220
218
221
219
## View the generated data
222
220
223
-
You can see all of the messages that arrive at your IoT hub by running **Azure IoT Hub: Start Monitoring Built-in Event Endpoint** in the command palette.
221
+
You can see all of the messages that arrive at your IoT hub from all your devices by running **Azure IoT Hub: Start Monitoring Built-in Event Endpoint** in the command palette. To stop monitoring messages, run the command **Azure IoT Hub: Stop Monitoring Built-in Event Endpoint** in the command palette.
224
222
225
-
You can also filter the view to see all of the messages that arrive at your IoT hub from a specific device. Right-click the device in the **Azure IoT Hub Devices** section and select **Start Monitoring Built-in Event Endpoint**.
226
-
227
-
To stop monitoring messages, run the command **Azure IoT Hub: Stop Monitoring Built-in Event Endpoint** in the command palette.
223
+
You can also filter the view to see all of the messages that arrive at your IoT hub from a specific device. Right-click the device in the **Azure IoT Hub** > **Devices** section of the Visual Studio Code explorer and select **Start Monitoring Built-in Event Endpoint**.
0 commit comments