Skip to content

Contact sales

By filling out this form and clicking submit, you acknowledge our privacy policy.
  • Labs icon Lab
  • A Cloud Guru
Azure icon

Manage Azure Cosmos DB with Declarative and Imperative Code

In this hands-on lab, you will export an existing Azure Resource Manager (ARM) template that describes an Azure Cosmos DB for NoSQL account and database. Then, you will store it as a template spec in the lab subscription. After editing the template spec to make two changes to the Cosmos DB account resources, you will use the Cloud Shell to deploy the changed ARM template and then confirm the changes in the Azure portal. If you are comfortable navigating the Azure portal, and have at least some experience with basic ARM templates and Azure CLI commands, you will have the best opportunity to successfully complete the lab objectives without assistance. Novices, however, are provided with enough information, tips, and hints to work on their own as much as possible before making use of the lab guide and solution videos.

Azure icon

Path Info

Clock icon Beginner
Clock icon 30m
Clock icon Dec 16, 2022

Contact sales

By filling out this form and clicking submit, you acknowledge our privacy policy.

Table of Contents

  1. Challenge


    1. Open an incognito or in-private window, and log in to the Azure portal using the username and password provided in the lab environment.
    2. From within the portal, initiate the Cloud Shell, and when prompted, select a Bash shell (versus PowerShell). When prompted again, set up the backing storage. Be sure that you select Show advanced settings and not Create storage. The latter will cause an error. Set up a new storage account with a universally unique name.
    3. Wait for the command prompt to appear.
  2. Challenge

    Export and Save an ARM Template as a Template Spec

    In this objective, you will use the existing Azure Cosmos for NoSQL account as the basis for creating a template spec and then update that template spec to change the default consistency level for the account and to create a new container.

    1. Navigate to the Azure Cosmos DB account predeployed in the lab environment.
    2. View the account's ARM template, and launch the wizard to add the template to the template spec library.
    3. Work through the wizard, including editing the template to perform the following actions:
      • Change the default consistency level for the Cosmos DB account from Session to Eventual.
      • Create another container in the LabDB database that is identical to the existing container called LabContainer, and assign it this exact name: AnotherLabContainer.
    4. Confirm the template is stored in the template spec library.

    Tips and Hints

    • You may find it easier to edit the template JSON using the editor in Cloud Shell or an IDE, such as Visual Studio Code.
    • If you decide to copy-paste existing container-related resources in the template, be sure to replace any references to the existing LabContainer.

      Hint: In every case, there is more than one place you need to edit.

    • If you do not specify container throughput settings, the deployment will default to a provisioned throughput of 400 RU/s.
  3. Challenge

    Deploy Template Spec Using Cloud Shell

    In this objective, you will use the Azure CLI in the Cloud Shell to apply the changes you made in the ARM template stored in the template specs library.

    1. Navigate to the Cloud Shell you initialized in the housekeeping task. If the Cloud Shell has timed out, reconnect.
    2. Use the Azure CLI at the command prompt to list the template specs currently stored in the Azure subscription.
    3. Use the Azure CLI and the information provided in the prior step to show the details of the template spec you created in the last objective.
    4. Use the Azure CLI and the information provided in the prior step to deploy the template spec into the existing resource group, with the intended effect of updating the default consistency level on the existing Cosmos DB account and adding a new container to the existing LabDB database.
    5. When the deployment is complete, navigate to the Cosmos DB account in the Azure portal to confirm the changes expressed in the ARM template are reflected on the resource.

    Tips and Hints

    • The base command to list template specs is az ts list.
    • The base command to show the specific details in a given template spec is az ts show, and you will need to pass the --template-spec argument.
    • The base command to deploy resources in the Azure CLI is az deployment group create.
    • The arguments required to deploy resources using a template spec include, at a minimum, --resource group and --template-spec.
    • In order to fully identify the template spec you stored, you will need to append the template spec ID with /versions/[x], where x is whatever version you last assigned when you stored the template spec.

The Cloud Content team comprises subject matter experts hyper focused on services offered by the leading cloud vendors (AWS, GCP, and Azure), as well as cloud-related technologies such as Linux and DevOps. The team is thrilled to share their knowledge to help you build modern tech solutions from the ground up, secure and optimize your environments, and so much more!

What's a lab?

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Provided environment for hands-on practice

We will provide the credentials and environment necessary for you to practice right within your browser.

Guided walkthrough

Follow along with the author’s guided walkthrough and build something new in your provided environment!

Did you know?

On average, you retain 75% more of your learning if you get time for practice.

Start learning by doing today

View Plans