Create an IoT hub using the Azure IoT Tools for Visual Studio Code

This article shows you how to use the Azure IoT Tools for Visual Studio Code to create an Azure IoT hub. You can create one without an existing IoT project or create one from an existing IoT project.

Note

We recommend that you use the Azure Az PowerShell module to interact with Azure. See Install Azure PowerShell to get started. To learn how to migrate to the Az PowerShell module, see Migrate Azure PowerShell from AzureRM to Az.

Prerequisites

Create an IoT hub without an IoT Project

The following steps show how to create an IoT Hub without an IoT Project in Visual Studio Code (VS Code).

  1. In VS Code, open the Explorer view.

  2. At the bottom of the Explorer, expand the Azure IoT Hub section.

    A screenshot that shows the location of the Azure IoT Hub section in VS Code.

  3. Select Create IoT Hub from the list in the Azure IoT Hub section.

    A screenshot that shows the location of the Create IoT Hub list item in VS Code.

  4. A pop-up will show in the bottom-right corner to let you sign in to Azure for the first time, if you're not signed in already.

  5. From the command palette at the top of VS Code, select your Azure subscription.

  6. Select your resource group.

  7. Select a location.

  8. Select a pricing tier.

  9. Enter a globally unique name for your IoT hub, then press Enter.

  10. Wait a few minutes until the IoT hub is created. You'll see a confirmation in the output console.

Create an IoT hub and device in an existing IoT project

The following steps show how to create an IoT Hub and register a device to the hub within an existing IoT project in Visual Studio (VS) Code.

This method allows you to provision in VS Code without leaving your development environment.

  1. In the new opened project window, click F1 to open the command palette, type and select Azure IoT Device Workbench: Provision Azure Services....

    A screenshot that shows how to open the command palette in VS Code.

    Note

    If you have not signed in Azure. Follow the pop-up notification for signing in.

  2. Select the subscription you want to use.

    A screenshot that shows how to choose your Azure subscription in VS Code.

  3. Select an existing resource group or create a new resource group.

    A screenshot that shows how to choose a resource group or create a new one in VS Code.

  4. In the resource group you specified, follow the prompts to select an existing IoT Hub or create a new Azure IoT Hub.

    A screenshot that shows the first prompt in choosing an existing IoT Hub in VS Code.

    A screenshot that shows the second prompt in choosing an existing IoT Hub in VS Code.

    A screenshot that shows the third prompt in choosing an existing IoT Hub in VS Code.

  5. In the output window, you'll see the Azure IoT Hub provisioned.

    A screenshot that shows the output window in VS Code.

  6. Select or create a new IoT Hub Device in the Azure IoT Hub you provisioned.

    A screenshot that shows the fourth prompt in choosing an existing IoT Hub in VS Code.

    A screenshot that shows an example of an existing IoT Hub in VS Code.

  7. Now you have an Azure IoT Hub provisioned and a device created in it. The device connection string will be saved in VS Code.

    A screenshot that shows IoT Hub details in the output window in VS Code.

Tip

To delete a device from your IoT hub, use the Azure IoT Hub: Delete Device option from the Command Palette. There is no option to delete your IoT hub in Visual Studio Code, however you can delete your hub in the Azure portal.

Next steps

Now that you've deployed an IoT hub using the Azure IoT Tools for Visual Studio Code, explore these articles: