Skip to content

Commit 7a70d4a

Browse files
committed
contd
1 parent aa8e5bd commit 7a70d4a

File tree

1 file changed

+29
-33
lines changed

1 file changed

+29
-33
lines changed

articles/iot-dps/tutorial-custom-allocation-policies.md

Lines changed: 29 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -51,30 +51,26 @@ In this section, you use the Azure Cloud Shell to create a provisioning service
5151

5252
The DPS and IoT Hub names must be globally unique. Replace the `SUFFIX` placeholder with your own value.
5353

54-
Also, the Azure Function code you create later in this tutorial looks for IoT hubs that have either `-toasters-` or `-heatpups-` in their names. If you change the suggested values, make sure to use names that contain the required substrings.
55-
56-
### [Bash](#tab/bash)
54+
Also, the Azure Function code you create later in this tutorial looks for IoT hubs that have either `-toasters-` or `-heatpumps-` in their names. If you change the suggested values, make sure to use names that contain the required substrings.
5755

5856
```bash
57+
#!/bin/bash
5958
export RESOURCE_GROUP="contoso-us-resource-group"
6059
export LOCATION="westus"
6160
export DPS="contoso-provisioning-service-SUFFIX"
6261
export TOASTER_HUB="contoso-toasters-hub-SUFFIX"
6362
export HEATPUMP_HUB="contoso-heatpumps-hub-SUFFIX"
6463
```
6564

66-
### [PowerShell](#tab/powershell)
67-
6865
```powershell
66+
# PowerShell
6967
$env:RESOURCE_GROUP = "contoso-us-resource-group"
7068
$env:LOCATION = "westus"
7169
$env:DPS = "contoso-provisioning-service-SUFFIX"
7270
$env:TOASTER_HUB = "contoso-toasters-hub-SUFFIX"
7371
$env:HEATPUMP_HUB = "contoso-heatpumps-hub-SUFFIX"
7472
```
7573

76-
---
77-
7874
> [!TIP]
7975
> The commands used in this tutorial create resources in the West US location by default. We recommend that you create your resources in the region nearest you that supports Device Provisioning Service. You can view a list of available locations by going to the [Azure Status](https://azure.microsoft.com/status/) page and searching for "Device Provisioning Service". In commands, locations can be specified either in one word or multi-word format; for example: westus, West US, WEST US, etc. The value is not case sensitive.
8076
@@ -113,53 +109,53 @@ In this section, you use the Azure Cloud Shell to create a provisioning service
113109
5. Run the following two commands to get the connection strings for the hubs you created.
114110
115111
```azurecli-interactive
116-
TOASTER_HUB_CONNECTION_STRING=$(az iot hub connection-string show --hub-name $TOASTER_HUB --key primary --query connectionString -o tsv)
117-
HEATPUMP_HUB_CONNECTION_STRING=$(az iot hub connection-string show --hub-name HEATPUMP_HUB --key primary --query connectionString -o tsv)
112+
az iot hub connection-string show --hub-name $TOASTER_HUB --key primary --query connectionString -o tsv
113+
az iot hub connection-string show --hub-name $HEATPUMP_HUB --key primary --query connectionString -o tsv
118114
```
119115
120-
6. Run the following commands to link the hubs to the DPS resource. Replace the DPS resource name with the name you chose in each command:
116+
6. Run the following commands to link the hubs to the DPS resource. Replace the placeholders with the hub connection strings from the previous step.
121117
122118
```azurecli-interactive
123-
az iot dps linked-hub create --dps-name $DPS --resource-group $RESOURCE_GROUP --connection-string $TOASTER_HUB_CONNECTION_STRING --location $LOCATION
124-
az iot dps linked-hub create --dps-name $DPS --resource-group $RESOURCE_GROUP --connection-string $HEATPUMP_HUB_CONNECTION_STRING --location $LOCATION
119+
az iot dps linked-hub create --dps-name $DPS --resource-group $RESOURCE_GROUP --location $LOCATION --connection-string <toaster_hub_connection_string>
120+
az iot dps linked-hub create --dps-name $DPS --resource-group $RESOURCE_GROUP --location $LOCATION --connection-string <heatpump_hub_connection_string>
125121
```
126122
127123
## Create the custom allocation function
128124
129125
In this section, you create an Azure function that implements your custom allocation policy. This function decides which divisional IoT hub a device should be registered to based on whether its registration ID contains the string **-contoso-tstrsd-007** or **-contoso-hpsd-088**. It also sets the initial state of the device twin based on whether the device is a toaster or a heat pump.
130126
131-
1. Sign in to the [Azure portal](https://portal.azure.com). From your home page, select **+ Create a resource**.
132-
133-
2. In the *Search the Marketplace* search box, type "Function App". From the drop-down list select **Function App**, and then select **Create**.
134-
135-
3. On the **Function App** create page, under the **Basics** tab, enter the following settings for your new function app and select **Review + create**:
136-
137-
**Resource Group**: Select the **contoso-us-resource-group** to keep all resources created in this tutorial together.
138-
139-
**Function App name**: Enter a unique function app name. This example uses **contoso-function-app-1098**.
127+
1. Sign in to the [Azure portal](https://portal.azure.com).
140128
141-
**Publish**: Verify that **Code** is selected.
129+
1. In the search box, search for and select **Function App**.
142130
143-
**Runtime Stack**: Select **.NET** from the drop-down.
131+
1. Select **Create** or **Create Function App**.
144132
145-
**Version**: Select **3.1** from the drop-down.
133+
1. On the **Function App** create page, under the **Basics** tab, enter the following settings for your new function app and select **Review + create**:
146134
147-
**Region**: Select the same region as your resource group. This example uses **West US**.
135+
| Parameter | Value |
136+
|--------------------|------------------------------|
137+
| **Subscription** | Make sure that the subscription where you created the resources for this tutorial is selected. |
138+
| **Resource Group** | Select the resource group that you created in the previous section. The default is **contoso-us-resource-group**. |
139+
| **Function App name** | Provide a name for your function app. |
140+
| **Publish** | Code |
141+
| **Runtime Stack** | .NET |
142+
| **Version** | 3.1 |
143+
| **Region** | West US |
148144
149145
> [!NOTE]
150146
> By default, Application Insights is enabled. Application Insights is not necessary for this tutorial, but it might help you understand and investigate any issues you encounter with the custom allocation. If you prefer, you can disable Application Insights by selecting the **Monitoring** tab and then selecting **No** for **Enable Application Insights**.
151147
152148
![Create an Azure Function App to host the custom allocation function](./media/tutorial-custom-allocation-policies/create-function-app.png)
153149
154-
4. On the **Summary** page, select **Create** to create the function app. Deployment may take several minutes. When it completes, select **Go to resource**.
150+
1. On the **Summary** page, select **Create** to create the function app. Deployment may take several minutes. When it completes, select **Go to resource**.
155151
156-
5. On the left pane of the function app **Overview** page, select **Functions** and then **+ Create** to add a new function.
152+
1. On the left pane of the function app **Overview** page, select **Functions** and then **+ Create** to add a new function.
157153
158-
6. On the **Create function** page, make sure that **Development environment** is set to **Develop in portal**. Then select the **HTTP Trigger** template followed by the **Create** button.
154+
1. On the **Create function** page, make sure that **Development environment** is set to **Develop in portal**. Then select the **HTTP Trigger** template followed by the **Create** button.
159155
160-
7. When the **HttpTrigger1** function opens, select **Code + Test** on the left pane. This allows you to edit the code for the function. The **run.csx** code file should be opened for editing.
156+
1. When the **HttpTrigger1** function opens, select **Code + Test** on the left pane. This allows you to edit the code for the function. The **run.csx** code file should be opened for editing.
161157
162-
8. Reference required NuGet packages. To create the initial device twin, the custom allocation function uses classes that are defined in two NuGet packages that must be loaded into the hosting environment. With Azure Functions, NuGet packages are referenced using a *function.proj* file. In this step, you save and upload a *function.proj* file for the required assemblies. For more information, see [Using NuGet packages with Azure Functions](../azure-functions/functions-reference-csharp.md#using-nuget-packages).
158+
1. Reference required NuGet packages. To create the initial device twin, the custom allocation function uses classes that are defined in two NuGet packages that must be loaded into the hosting environment. With Azure Functions, NuGet packages are referenced using a *function.proj* file. In this step, you save and upload a *function.proj* file for the required assemblies. For more information, see [Using NuGet packages with Azure Functions](../azure-functions/functions-reference-csharp.md#using-nuget-packages).
163159
164160
1. Copy the following lines into your favorite editor and save the file on your computer as *function.proj*.
165161
@@ -175,11 +171,11 @@ In this section, you create an Azure function that implements your custom alloca
175171
</Project>
176172
```
177173
178-
2. Select the **Upload** button located above the code editor to upload your *function.proj* file. After uploading, select the file in the code editor using the drop-down box to verify the contents.
174+
1. Select the **Upload** button located above the code editor to upload your *function.proj* file. After uploading, select the file in the code editor using the drop-down box to verify the contents.
179175
180-
3. Select the *function.proj* file in the code editor and verify its contents. If the *function.proj* file is empty copy the lines above into the file and save it. (Sometimes the upload will create the file without uploading the contents.)
176+
1. Select the *function.proj* file in the code editor and verify its contents. If the *function.proj* file is empty copy the lines above into the file and save it. (Sometimes the upload will create the file without uploading the contents.)
181177
182-
9. Make sure *run.csx* for **HttpTrigger1** is selected in the code editor. Replace the code for the **HttpTrigger1** function with the following code and select **Save**:
178+
1. Make sure *run.csx* for **HttpTrigger1** is selected in the code editor. Replace the code for the **HttpTrigger1** function with the following code and select **Save**:
183179
184180
```csharp
185181
#r "Newtonsoft.Json"

0 commit comments

Comments
 (0)