Introduction to Azure CLI

Get introduced to various command interface tools that Azure supports—Azure CLI, Azure PowerShell, and Azure Cloudshell—and their usage.

What are Azure command-line tools?

Azure command-line tools help manage most Azure resources and services-related tasks by allowing us to automate and scale our tasks in Azure. They can also be grouped into a bash file, making sharing easy.

Azure mainly supports three types of command-line tools.

  1. Azure CLI: This is an extension to the Windows command-line environment. The commands would be in Bash format.
  2. PowerShell: This is an extension to the Windows PowerShell environment. The commands need to be in cmdlet format.
  3. Azure Cloud Shell: This supports Bash and PowerShell environments via a web interface. There’s no installation required.

What is Azure CLI?

The Azure Command-Line Interface (CLI) is a simple, cross-platform command-line tool to connect to Azure. Using it, we can do the following:

  • Create and manage Azure resources (VMs/databases).
  • Execute administrative commands on Azure resources (workgroups, storage accounts, and so on).
  • Leverage existing services (ML).

The tool is designed to run quickly with Azure, with faster development and automation.

We can launch a shell on Windows or Bash on Linux or macOS. We can bundle the CLI commands into a shell script to automate repetitive tasks. The latest version of Azure CLI v2 supports training, running, and deploying ML models using the Azure ml extension. Azure functionalities can also be achieved using the GUI-friendly Azure Studio and developer-friendly Azure SDK.

Azure Cloud Shell: We can access the Azure CLI from Azure Cloud Shell as well. It’s convenient to start immediately without installing or requiring a separate desktop machine. Azure Cloud Shell includes an integrated file editor built from the open-source Monaco Editor.

Type shell.azure.com into your browser.

Alternatively, select the Cloud Shell icon from the Azure portal.

Press + to interact
Choosing the shell option
Choosing the shell option

We can choose one of two options—Bash or PowerShell—from the shell options. If we select Bash, it launches the Bash console. We can switch it to PowerShell at any later point in time.

Press + to interact
Executing shell commands from Cloud shell
Executing shell commands from Cloud shell

After selecting the suitable shell environment, we can choose the correct subscription (if we have multiple subscriptions) and select storage. That’s all! We’re good to go! We can switch the command-line environment to Bash or PowerShell whenever we want.

Cloud Shell Features

  • It runs a temporary session and runs for each user.
  • If Cloud Shell is idle for 20 minutes, it will timeout to optimize the resources. It is also meant to work in interactive mode; therefore, any long-running processes are timed out.
  • We have to mount a file share in the shell environment.
  • We will have to use the same file share for both the Bash and PowerShell environments.
  • A 5-GB image held in the file share is reserved for $HOME.
  • User permissions would be the same as any Linux user.

PowerShell: Azure PowerShell offers a set of cmdlets for managing Azure resources. The syntax is similar to Windows PowerShell. It provides solid features for automating repetitive tasks.

The Az PowerShell module works with PowerShell 7.0.6 LTS and PowerShell 7.1.3 or higher on all platforms, including Windows, macOS, and Linux. It can also be installed locally on these operating systems. It’s also compatible with Windows PowerShell 5.1.

Which command-line tool to use

Azure CLI is a developer-friendly environment that relieves us from setting up all the required environments step-by-step (unlike Azure SDK). It also gives us greater freedom, customization, and faster development (better than Azure Studio). We can also automate and schedule jobs using Azure CLI. Once we install Azure CLI and launch the command prompt, we’re good to go.

Azure CLI and Azure PowerShell are cross-platform command-line tools and offer similar functionalities.

The Azure CLI syntax is similar to that of Bash scripting. Azure CLI works the same way as the Linux scripting system. Azure CLI commands can be executed from the PowerShell environment as well. Azure CLI outputs in JSON, YAML, and various output formats.

Azure PowerShell is a seamless fit for developers with Windows backgrounds. PowerShell cmdlets follow a verb-noun naming scheme, and the output is returned as objects.

Azure Cloud Shell doesn’t need to be in sync with a recent version of Azure PowerShell and Azure CLI because the publishing schedule for all three tools is different. Azure Cloud Shell is more suitable for learning and intended for small-scale jobs. It’s not recommended for enterprise-scale applications.

This course will set up the Azure environment, create ML models, and deploy them as a service—using the Azure CLI for everything.