Exercise - Create Azure Cosmos DB resources in Visual Studio Code
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
Go to the Visual Studio Marketplace, and install the Azure Databases extension for Visual Studio Code.
When the extension tab loads in Visual Studio Code, select Install.
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
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.
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.
Select Azure icon on the left menu.
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 Subscriptionscommand.
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.
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.
In the text box for capacity model. select Provisioned Throughput, and press Enter.
In the text box for resource group, select
[sandbox resource group name], and press Enter.
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.
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).
Create an Azure Cosmos DB database and collection in Visual Studio Code
Now let's create a new database and collection for your customers.
In the Azure: Cosmos DB pane, right-click your new account, and then select Create Database.
In the text box at the top of the pane, enter
Usersfor the database name, and then press Enter.
WebCustomersfor the id for your collection name, and then press Enter.
userIdfor partition key, and then press Enter.
Accept the default
400for throughput capacity, and then press Enter.
Expand the account in the Azure: Cosmos DB pane, and the new Users database and WebCustomers collection appear.
Now that you have your Azure Cosmos DB account, lets get to work in Visual Studio Code!