Azure CLI 2.0: Create Azure IoT Hub

Chris Pietschmann Chris Pietschmann on Jul 01, 2019

It's really easy to provision an instance of Azure IoT Hub using the Azure Portal. However, there are times when you need to automate the task. You can use the Azure CLI to create new instances of Azure IoT Hub when you need to automate the task. This can help with DevOps processes to be able to setup mutliple environments with the exact same configurations; such as deploying stage or production evironments that are teh same as the development environment.

Create Azure IoT Hub

Follow these steps to create an Azure IoT Hub service instance using the Azure CLI (cross-platform command-line tools):

  1. Open an Azure CLI command prompt, or an instance of the Azure Cloud Shell.

  2. To create a new instance of the Azure IoT HUb service, the following command can be used:

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

--name: The Name parameter is used to specify the name of the IoT Hub service. This is also used as part of the DNS endpoint for the service, so it will need to be unique.

Tip: The IoT Hub Name must meet the following requirements:

  • must be unique across all customers using IoT Hub within Azure.
  • must be between 3 and 50 characters long
  • can only be alphanumeric characters

--resource-group: The Resource Group is how the IoT Hub service is organized within your Azure Subscription.

Once this command is executed, a new instance of the Azure IoT Hub service will be created and ready to use. Be sure to set the required parameters. You can reference the following section of this guide for more information about the --sku parameter.

Azure IoT HUb SKUs

The --sku parameter of the az iot hub create command must be set to a valid pricing tier (SKU) for Azure IoT Hub.

Here are the pricing tiers with a little information about their limits and scalability targets:

Basic tier

SKU Messages / day per Unit Message meter size
B1 400,000 4 KB
B2 6,000,000 4 KB
B3 300,000,000 4 KB

Standard tier

SKU Messages / day per Unit Message meter size
F1 8,000 0.5 KB
S1 400,000 4 KB
S2 6,000,000 4 KB
S3 300,000,000 4 KB

Please refer to the Azure IoT Hub Pricing page for further information about the pricing tiers available.

Here's an example command to create an Azure IoT Hub using the Standard S2 pricing tier:

az iot hub create \
    --name AppIoTHub \
    --resource-group AppRG \
    --sku S2