Exercise - Create Azure Cosmos DB resources in Visual Studio Code

Completed

The Azure Databases extension for Visual Studio Code simplifies account, database, and collection creation by enabling you to create resources using the command window.

In this unit, you will install the Azure Databases extension for Visual Studio, and then use it to create an account, database, and collection.

Install the Azure Databases extension for Visual Studio

  1. Go to the Visual Studio Marketplace, and install the Azure Databases extension for Visual Studio Code.

  2. When the extension tab loads in Visual Studio Code, select Install.

  3. After installation is complete, select Restart to update if required. You can restart by selecting the gear icon on the bottom left-hand corner.

    Visual Studio Code displays the Azure icon on the left side of the screen after the extension is installed and reloaded.

Create an Azure Cosmos DB account in Visual Studio Code

  1. In Visual Studio Code, sign in to Azure by selecting View > Command Palette, and then selecting Azure: Sign In. You must have the Azure Account extension installed to use Azure: Sign In.

    Important

    Log in to Azure using the same account used to create the sandbox. The sandbox provides access to a Concierge Subscription.

    Follow the prompts to copy and paste the code provided in the web browser, which authenticates your Visual Studio Code session.

  2. Select Azure icon on the left menu.

    Note

    If you do not see the Concierge Subscription listed, ensure you logged into Azure in Visual Studio Code using the same account used to create the sandbox. Additionally, if you have filtered your Azure subscriptions in the Azure Account extension, verify the Concierge Subscription is checked in the > Azure: Select Subscriptions command.

  3. Select Databases > right click Concierge Subscription, and select Create Server to start creating an Azure Cosmos DB account. You will be asked to select the subscription if you have more than one. Select Core (SQL) for the database option.

  4. In the text box at the top of the screen, enter a unique name for your Azure Cosmos DB account, and then press Enter. The account name can contain only lowercase letters, numbers and the '-' character, and must be between 3 and 31 characters.

  5. In the text box for capacity model. select Provisioned Throughput, and press Enter.

  6. In the text box for resource group, select [sandbox resource group name], and press Enter.

  7. In the text box for location, select a location close to yours from the options, and press Enter.

    The free sandbox allows you to create resources in a subset of the Azure global regions. Select a region from the following list when you create resources:

    • West US 2
    • South Central US
    • Central US
    • East US
    • West Europe
    • Southeast Asia
    • Japan East
    • Brazil South
    • Australia Southeast
    • Central India

    The output tab in Visual Studio Code displays the progress of the account creation. It takes a few minutes to complete.

  8. After the account is created, expand your Azure subscription in the Azure: Cosmos Databases pane. The extension displays the new Azure Cosmos database account. In the following image, the new account is named learning-modules (SQL).

    Screenshot of the Azure Cosmos DB Visual Studio Code extension with a callout highlighting the learning-modules account listed in the pane.

Create an Azure Cosmos DB database and collection in Visual Studio Code

Now let's create a new database and collection for your customers.

  1. In the Azure: Cosmos DB pane, right-click your new account, and then select Create Database.

  2. In the text box at the top of the pane, enter Users for the database name, and then press Enter.

  3. Enter WebCustomers for the id for your collection name, and then press Enter.

  4. Enter userId for partition key, and then press Enter.

  5. Accept the default 400 for throughput capacity, and then press Enter.

  6. Expand the account in the Azure: Cosmos DB pane, and the new Users database and WebCustomers collection appear.

    Animation showing the above instructions run through the Azure Cosmos DB extension in Visual Studio Code.

Now that you have your Azure Cosmos DB account, lets get to work in Visual Studio Code!