Permalink
Fetching contributors…
Cannot retrieve contributors at this time
89 lines (58 sloc) 3.19 KB
title description author ms.service services ms.topic ms.date ms.author
Create an IoT Hub using Azure CLI | Microsoft Docs
How to create an Azure IoT hub using Azure CLI.
robinsh
iot-hub
iot-hub
conceptual
08/23/2018
robinsh

Create an IoT hub using Azure CLI

[!INCLUDE iot-hub-resource-manager-selector]

This article shows you how to create an IoT hub using Azure CLI.

Prerequisites

To complete this how-to, you need an Azure subscription. If you don't have an Azure subscription, create a free account before you begin.

[!INCLUDE cloud-shell-try-it.md]

Sign in and set your Azure account

If you are running Azure CLI locally instead of using Cloud Shell, you need to sign in to your Azure account.

At the command prompt, run the login command:

```azurecli
az login
```

Follow the instructions to authenticate using the code and sign in to your Azure account through a web browser.

Create an IoT Hub

Use the Azure CLI to create a resource group and then add an IoT hub.

  1. When you create an IoT hub, you must create it in a resource group. Either use an existing resource group, or run the following command to create a resource group:

    az group create --name {your resource group name} --location westus
    

    [!TIP] The previous example creates the resource group in the West US location. You can view a list of available locations by running this command:

    az account list-locations -o table
  2. Run the following command to create an IoT hub in your resource group, using a globally unique name for your IoT hub:

    az iot hub create --name {your iot hub name} \
       --resource-group {your resource group name} --sku S1
    

    [!INCLUDE iot-hub-pii-note-naming-hub]

The previous command creates an IoT hub in the S1 pricing tier for which you are billed. For more information, see Azure IoT Hub pricing.

Remove an IoT Hub

You can use Azure CLI to delete an individual resource, such as an IoT hub, or delete a resource group and all its resources, including any IoT hubs.

To delete an IoT hub, run the following command:

az iot hub delete --name {your iot hub name} -\
  -resource-group {your resource group name}

To delete a resource group and all its resources, run the following command:

az group delete --name {your resource group name}

Next steps

To learn more about using an IoT hub, see the following articles: