It’s simple to provision an Azure IoT Hub service instance using the Azure Portal. However, there are time when you need a more DevOps style approach by scripting it. The Azure Powershell Az.IotHub
module can be used to manage commands for managing Azure IoT Hub resources. This method enables you to use the command-line directly or even write PowerShell scripts to deploy Azure IoT Hub in dev, stage, or even production environments.
Create Azure IoT Hub using PowerShell
Follow these steps to create an Azure IoT Hub service instance using the Azure PowerShell Az.IotHub
module:
-
Open an Azure PowerShell prompt, or an instance of the Azure Cloud Shell.
-
To create a new instance of the Azure IoT Hub service, the following command can be used:
New-AzIotHub -Name {iot-hub-name} ` -ResourceGroupName {resource-group-name} ` -SkuName {sku} ` -Unit {number-of-units} ` -Location {azure-region}
-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 is required to be unique.Naming Requirements: 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
- must only be alphanumeric characters
-ResourceGroupName
: 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-SkuName
parameters.
Azure IoT Hub SKUs (Pricing Tiers)
The -SkuName
parameter of the New-AzIotHub
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 (FREE) |
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 with the placeholders filled in to create an Azure IoT Hub using the Standard S1 pricing tier:
New-AzIoTHub -Name TestIoTHub59 -ResourceGroupName Test `
-SkuName S1 -Unit 1 -Location centralus
Install Azure PowerShell Az.IotHub Module
The New-AzIotHub
cmdlet is a part of the Azure PowerShell Az.IotHub
module. In order to use this module with Azure PowerShell, you will need to have the module installed.
You can use the following command within PowerShell to install the Az.IotHub
module:
Install-Module -Name Az.IotHub
Happy Scripting!