|
| 1 | +--- |
| 2 | +title: Create an IoT hub |
| 3 | +titleSuffix: Azure IoT Hub |
| 4 | +description: How to create, manage, and delete Azure IoT hubs through the Azure portal and CLI. Includes information about pricing tiers, scaling, security, and messaging configuration. |
| 5 | +author: kgremban |
| 6 | + |
| 7 | +ms.author: kgremban |
| 8 | +ms.service: iot-hub |
| 9 | +ms.topic: how-to |
| 10 | +ms.date: 06/10/2024 |
| 11 | +ms.custom: ['Role: Cloud Development'] |
| 12 | +--- |
| 13 | + |
| 14 | +# Create an IoT hub using the Azure portal |
| 15 | + |
| 16 | +This article describes how to create and manage an IoT hub. |
| 17 | + |
| 18 | +## Prerequisites |
| 19 | + |
| 20 | +* Depending on which tool you use, either have access to the [Azure portal](https://portal.azure.com) or [install the Azure CLI](/cli/azure/install-azure-cli). |
| 21 | + |
| 22 | +## Create an IoT hub |
| 23 | + |
| 24 | +### [Azure portal](#tab/portal) |
| 25 | + |
| 26 | +[!INCLUDE [iot-hub-include-create-hub](../../includes/iot-hub-include-create-hub.md)] |
| 27 | + |
| 28 | +### [Azure CLI](#tab/cli) |
| 29 | + |
| 30 | +Use the Azure CLI to create a resource group and then add an IoT hub. |
| 31 | + |
| 32 | +Use the [iz iot hub create](/cli/azure/iot/hub#az-iot-hub-create) command to create an IoT hub in your resource group, using a globally unique name for your IoT hub. For example: |
| 33 | + |
| 34 | +```azurecli-interactive |
| 35 | +az iot hub create --name <NEW_NAME_FOR_YOUR_IOT_HUB> \ |
| 36 | + --resource-group <RESOURCE_GROUP_NAME> --sku S1 |
| 37 | +``` |
| 38 | + |
| 39 | +[!INCLUDE [iot-hub-pii-note-naming-hub](../../includes/iot-hub-pii-note-naming-hub.md)] |
| 40 | + |
| 41 | +The previous command creates an IoT hub in the S1 pricing tier for which you're billed. For more information, see [Azure IoT Hub pricing](https://azure.microsoft.com/pricing/details/iot-hub/). |
| 42 | + |
| 43 | +--- |
| 44 | + |
| 45 | +## Update an IoT hub |
| 46 | + |
| 47 | +You can change the settings of an existing IoT hub after it's created. Here are some properties you can set for an IoT hub: |
| 48 | + |
| 49 | +* **Pricing and scale**: Migrate to a different tier or set the number of IoT Hub units. |
| 50 | + |
| 51 | +* **IP Filter**: Specify a range of IP addresses for the IoT hub to accept or reject. |
| 52 | + |
| 53 | +* **Properties**: A list of properties that you can copy and use elsewhere, such as the resource ID, resource group, location, and so on. |
| 54 | + |
| 55 | +### [Azure portal](#tab/portal) |
| 56 | + |
| 57 | +### [Azure CLI](#tab/cli) |
| 58 | + |
| 59 | +Use the [az iot hub update](/cli/azure/iot/hub#az-iot-hub-update) command to make changes to an existing IoT hub. |
| 60 | + |
| 61 | +--- |
| 62 | + |
| 63 | +## Connect to an IoT hub |
| 64 | + |
| 65 | +Provide access permissions to applications and services that use IoT Hub functionality. |
| 66 | + |
| 67 | +### Connect with a connection string |
| 68 | + |
| 69 | +Connection strings are an easy way to get started with IoT Hub, and are used in many samples and tutorials, but aren't recommended for production scenarios. |
| 70 | + |
| 71 | +Shared access policies define permissions for devices and services to connect to IoT Hub. The built-in policies provide one or more of the following permissions. You should always provide the least necessary permissions for a given scenario. |
| 72 | + |
| 73 | +* The **Registry Read** and **Registry Write** permissions grant read and write access rights to the identity registry. These permissions are used by back-end cloud services to manage device identities. |
| 74 | + |
| 75 | +* The **Service Connect** permission grants permission to access service endpoints. This permission is used by back-end cloud services to send and receive messages from devices. It's also used to update and read device twin and module twin data. |
| 76 | + |
| 77 | +* The **Device Connect** permission grants permissions for sending and receiving messages using the IoT Hub device-side endpoints. This permission is used by devices to send and receive messages from an IoT hub or update and read device twin and module twin data. It's also used for file uploads. |
| 78 | + |
| 79 | +For information about the access granted by specific permissions, see [IoT Hub permissions](./iot-hub-dev-guide-sas.md#access-control-and-permissions). |
| 80 | + |
| 81 | + |
| 82 | +#### [Azure portal](#tab/portal) |
| 83 | + |
| 84 | +To get the IoT Hub connection string for the **service** policy, follow these steps: |
| 85 | + |
| 86 | +1. In the [Azure portal](https://portal.azure.com), select **Resource groups**. Select the resource group where your hub is located, and then select your hub from the list of resources. |
| 87 | + |
| 88 | +1. On the left-side pane of your IoT hub, select **Shared access policies**. |
| 89 | + |
| 90 | +1. From the list of policies, select the **service** policy. |
| 91 | + |
| 92 | +1. Copy the **Primary connection string** and save the value. |
| 93 | + |
| 94 | + |
| 95 | +#### [Azure CLI](#tab/cli) |
| 96 | + |
| 97 | +IoT hubs are created with several default access policies. One such policy is the **service** policy, which provides sufficient permissions for a service to read and write the IoT hub's endpoints. Run the following command to get a connection string for your IoT hub that adheres to the service policy: |
| 98 | + |
| 99 | +```azurecli-interactive |
| 100 | +az iot hub connection-string show --hub-name YOUR_IOT_HUB_NAME --policy-name service |
| 101 | +``` |
| 102 | + |
| 103 | +The service connection string should look similar to the following example: |
| 104 | + |
| 105 | +```javascript |
| 106 | +"HostName=<IOT_HUB_NAME>.azure-devices.net;SharedAccessKeyName=service;SharedAccessKey=<SHARED_ACCESS_KEY>" |
| 107 | +``` |
| 108 | + |
| 109 | +--- |
| 110 | + |
| 111 | +### Connect with role assignments |
| 112 | + |
| 113 | +In production scenarios, we recommend using Microsoft Entra ID and Azure role-based access control (Azure RBAC) for connecting to IoT Hub. For more information, see [Control access to IoT Hub by using Microsoft Entra ID](./authenticate-authorize-azure-ad.md). |
| 114 | + |
| 115 | +## Delete an IoT hub |
| 116 | + |
| 117 | +### [Azure portal](#tab/portal) |
| 118 | + |
| 119 | +To delete an IoT hub, open your IoT hub in the Azure portal, then choose **Delete**. |
| 120 | + |
| 121 | +:::image type="content" source="./media/iot-hub-create-through-portal/delete-iot-hub.png" alt-text="Screenshot showing where to find the delete button for an IoT hub in the Azure portal." lightbox="./media/iot-hub-create-through-portal/delete-iot-hub.png"::: |
| 122 | + |
| 123 | +### [Azure CLI](#tab/cli) |
| 124 | + |
| 125 | +To [delete an IoT hub](/cli/azure/iot/hub#az-iot-hub-delete), run the following command: |
| 126 | + |
| 127 | +```azurecli-interactive |
| 128 | +az iot hub delete --name {your iot hub name} -\ |
| 129 | + -resource-group {your resource group name} |
| 130 | +``` |
| 131 | + |
| 132 | +--- |
| 133 | + |
| 134 | +## Next steps |
| 135 | + |
| 136 | +Learn more about managing Azure IoT Hub: |
| 137 | + |
| 138 | +* [Message routing with IoT Hub](how-to-routing-portal.md) |
| 139 | +* [Monitor your IoT hub](monitor-iot-hub.md) |
0 commit comments