Skip to content

Commit f7ffad6

Browse files
authored
Update how-to-routing-azure-cli.md
1 parent 865ff62 commit f7ffad6

File tree

1 file changed

+48
-2
lines changed

1 file changed

+48
-2
lines changed

articles/iot-hub/how-to-routing-azure-cli.md

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,16 @@ To learn more about how routing works in IoT Hub, see [Use IoT Hub message routi
2020
**Azure CLI**
2121

2222
[!INCLUDE [azure-cli-prepare-your-environment-no-header](../../includes/azure-cli-prepare-your-environment-no-header.md)]
23+
> [!NOTE]
24+
> Azure CLI installation by default includes the Azure IoT CLI extension, however for some preview features, please upgrade the IoT CLI extension following the instructions [here](https://github.com/Azure/azure-iot-cli-extension).
2325
2426
**IoT Hub and an endpoint service**
2527

2628
You need an IoT hub and at least one other service to serve as an endpoint to an IoT hub route.
2729

2830
* An IoT hub in your [Azure subscription](https://azure.microsoft.com/free/?WT.mc_id=A261C142F). If you don't have a hub yet, you can follow the steps in [Create an IoT hub using the Azure CLI](iot-hub-create-using-cli.md).
2931

30-
You can choose which Azure service (Event Hubs, Service Bus queue or topic, or Azure Storage) endpoint that you'd like to connect with your IoT Hub route. You only need one service to assign the endpoint to a route.
32+
You can choose which Azure service (Event Hubs, Service Bus queue or topic, Azure Storage, or Azure Cosmos DB) endpoint that you'd like to connect with your IoT Hub route.
3133

3234
# [Event Hubs](#tab/eventhubs)
3335

@@ -153,6 +155,24 @@ You can choose an Azure Storage resource (account and container).
153155

154156
For more information, see [Create a storage account](/azure/storage/common/storage-account-create?tabs=azure-cli).
155157

158+
# [Cosmos DB](#tab/cosmosdb)
159+
160+
You can choose a Cosmos DB endpoint.
161+
162+
### Create an Azure Storage resource with container
163+
164+
1. Create a new Cosmos DB account for SQL API
165+
```azurecli
166+
az group create --name my-resource-group --location "eastus"
167+
az cosmosdb create --name my-cosmosdb-account --resource-group my-resource-group
168+
```
169+
2. Create a Cosmos DB container
170+
```azurecli
171+
az cosmosdb sql database create --account-name my-cosmosdb-account --resource-group my-resource-group --name my-cosmosdb-database
172+
az cosmosdb sql container create --account-name my-cosmosdb-account --resource-group my-resource-group --database-name my-cosmosdb-database --name my-cosmosdb-database-container --partition-key-path "/my/path"
173+
```
174+
For more information, see [Create an Azure Cosmos DB for NoSQL](/cosmos-db/scripts/cli/nosql/create).
175+
156176
---
157177

158178
## Create an endpoint
@@ -245,6 +265,32 @@ References used in the following commands:
245265

246266
For more parameter options, see [az iot hub routing-endpoint](/cli/azure/iot/hub/routing-endpoint).
247267

268+
# [Cosmos DB](#tab/cosmosdb)
269+
270+
References used in the following commands:
271+
* [az cosmosdb](/cli/azure/cosmosdb)
272+
* [az iot hub](/cli/azure/iot/hub)
273+
274+
### Create a Cosmos DB endpoint
275+
276+
1. Find the Cosmos DB connection string and copy for later use.
277+
278+
```azurecli
279+
az cosmosdb keys list --name my-cosmosdb-account --resource-group my-resource-group --type connection-strings
280+
```
281+
282+
1. Create your custom endpoint. Use the connection string in this command that you copied in the last step. The `endpoint-type` must be `eventhub`, otherwise all other values should be your own.
283+
284+
```azurecli
285+
az iot hub message-endpoint cosmosdb-collection create --resource-group my-resource-group --hub-name my-iot-hub --endpoint-name my-cosmosdb-endpoint --endpoint-account my-cosmosdb-account --database-name my-cosmosdb-database --collection my-cosmosdb-database-container --connection-string "copied-connection-string"
286+
```
287+
> [!NOTE]
288+
> If you are using managed identities instead of connection string, you have to use the following command to authenticate your identity to the CosmosDB account.
289+
To see all routing endpoint options, see [az iot hub routing-endpoint](/cli/azure/iot/hub/routing-endpoint).
290+
291+
```azurecli
292+
az cosmosdb sql role assignment create -a my-cosmosdb-account -g my-resource-group --scope '/' -n 'Cosmos DB Built-in Data Contributor' -p "IoT Hub System Assigned or User Assigned Identity"
293+
```
248294
---
249295

250296
## Create an IoT Hub route
@@ -411,4 +457,4 @@ az iot hub route delete --resource-group my-resource-group --hub-name my-iot-hub
411457

412458
In this how-to article you learned how to create a route and endpoint for your Event Hubs, Service Bus queue or topic, and Azure Storage.
413459

414-
To further your exploration into message routing, see [Tutorial: Send device data to Azure Storage using IoT Hub message routing](/azure/iot-hub/tutorial-routing?tabs=cli). In this tutorial, you'll create a storage route and test it with a device in your IoT hub.
460+
To further your exploration into message routing, see [Tutorial: Send device data to Azure Storage using IoT Hub message routing](/azure/iot-hub/tutorial-routing?tabs=cli). In this tutorial, you'll create a storage route and test it with a device in your IoT hub.

0 commit comments

Comments
 (0)