Create an IoT hub using the Azure CLI
You can use Azure CLI (azure.js) to create and manage Azure IoT hubs programmatically. This article shows you how to use the Azure CLI (azure.js) to create an IoT hub.
You can complete the task using one of the following CLI versions:
- Azure CLI (azure.js) – the CLI for the classic and resource management deployment models as described in this article.
- Azure CLI 2.0 (az.py) - the next generation CLI for the resource management deployment model.
To complete this tutorial, you need the following:
- An active Azure account. If you don't have an account, you can create a free account in just a couple of minutes.
- Azure CLI 0.10.4 or later. If you already have the Azure CLI installed, you can validate the current version at the command prompt with the following command:
Azure has two different deployment models for creating and working with resources: Azure Resource Manager and classic. The Azure CLI must be in Azure Resource Manager mode:
azure config mode arm
Set your Azure account and subscription
At the command prompt, login by typing the following command:
Use the suggested web browser and code to authenticate.
If you have multiple Azure subscriptions, connecting to Azure grants you access to all the Azure subscriptions associated with your credentials. You can view the Azure subscriptions, and identify which one is the default, using the command:
azure account list
To set the subscription context under which you want to run the rest of the commands use:
azure account set <subscription name>
If you do not have a resource group, you can create one named exampleResourceGroup:
azure group create -n exampleResourceGroup -l westus
The article Use the Azure CLI to manage Azure resources and resource groups provides more information about how to use the Azure CLI to manage Azure resources.
Create an IoT Hub
azure iothub create -g <resource-group> -n <name> -l <location> -s <sku-name> -u <units>
- resource-group. The resource group name. The format is case insensitive alphanumeric, underscore, and hyphen, 1-64 length.
- name. The name of the IoT hub to be created. The format is case insensitive alphanumeric and hyphen, 3-50 length.
- location. The location (azure region/datacenter) to provision the IoT hub.
- sku-name. The name of the sku, one of: [F1, S1, S2, S3]. For details about each sku, see Azure IoT Hub pricing. Currently, basic tiers are only available through the portal.
- units. The number of provisioned units. For details about unit limits, see Azure IoT Hub pricing.
The IoT hub will be publicly discoverable as a DNS endpoint, so make sure to avoid any sensitive information while naming it.
To see all the parameters available for creation, you can use the help command in command prompt:
azure iothub create -h
Quick example: To create an IoT Hub called exampleIoTHubName in the resource group exampleResourceGroup, run the following command:
azure iothub create -g exampleResourceGroup -n exampleIoTHubName -l westus -k s1 -u 1
This Azure CLI command creates an S1 Standard IoT Hub for which you are billed. You can delete the IoT hub exampleIoTHubName using following command:
azure iothub delete -g exampleResourceGroup -n exampleIoTHubName
To learn more about developing for IoT Hub, see the following article:
To further explore the capabilities of IoT Hub, see: