How To Access Azure Cloud Shell From Visual Studio Code

0
348

The Azure Cloud Shell is an integrated CLI experience available to Microsoft Azure cloud users. Usually available in either a Linux Bash shell or PowerShell prompt, you can also utilize the Azure Cloud Shell directly in the VS Code integrated development environment.

What Features Does the Azure Cloud Shell Offer?

  • Bash shell for Linux style commands
  • PowerShell for Windows familiar developers
  • Built-in PowerShell Modules
    • Az.Accounts
    • Az.Compute
    • Az.Network
    • Az.Resources
    • Az.Storage
    • AzureAD.Standard.Preview
    • AzurePSDrive
    • PSCloudShellUtility
  • Latest version of Azure CLI (az command) available to both Bash and PowerShell environments
  • Latest PowerShell available in Bash environment using pwsh runtime

The Azure Cloud Shell automatically manages authentication and setup for all associated modules and tools. This makes it quick and easy to get started managing your Azure environment from the command line.

Getting Started with the Azure Cloud Shell

Most users will start with the Azure Cloud Shell in one of two ways. Either through the Azure Portal and its inline shell access or through a direct web link to the Azure Shell.

Azure Portal Shell Access

Connecting to the shell via the Azure Portal is as simple as clicking on the terminal icon next to the search bar in the upper portion of the screen.

Starting the Azure Cloud Shell from within the Azure Portal.

As soon as you click on this icon, one of two shells will show, either the Bash or PowerShell terminal as seen below. In the first image, you will see that the Bash terminal has connected. If you use the dropdown to the upper left of the terminal, you will have the option for either Bash or PowerShell.

Launching the Azure Cloud Shell using the Bash terminal.
Launching the Azure Cloud Shell using the PowerShell terminal.

Direct Shell Access via Web

Another common method of starting the Azure Cloud Shell is through a direct link to the website itself. Navigating to https://shell.azure.com/ will open either the Bash or PowerShell terminal. If you are not logged in, you will be prompted to do so prior to access. Once authenticated, you will have immediate access to the same terminal as within the Azure Portal.

Accessing the Azure Cloud Shell via direct web link and utilizing PowerShell.
Accessing the Azure Cloud Shell via direct web link and utilizing Bash.

Integrating the Azure Cloud Shell with VS Code

Of course, as a developer, this may not be the most efficient method. A very popular editor released by Microsoft, VS Code, has become a well-integrated solution for access to many different Azure resources and notably the Azure Cloud Shell.

With an integrated development workflow and quick access to common Azure commands from within the editor itself, a lot of time and energy can be saved. What are the steps necessary to get started using the Azure Cloud Shell in VS Code?

The quickest and easiest way to get started is to install the official Azure Account extension from Microsoft. Navigate to the “Extension”s icon on the left-hand menu of VS Code and search for Azure Account. Once the extension has been located, click on the “Install” button. After installation, you might have to restart VS Code, but as soon as the extension is available, you will have access to a number of different commands.

Installing the Azure Account extension in VS Code.

To locate all the available commands, type ctrl-shift-p to open the command pane for VS Code. Click or select the “Azure: Open PowerShell in Cloud Shell” option.

Running the Open PowerShell in Cloud Shell command from the VS Code command pane.

If you are not already signed in through the Azure Account extension, a prompt will show. Click on “Sign In” to be taken to a webpage using your default browser that allows you to sign into your Azure account.

Signing into your Azure Account for the Azure Cloud Shell.

Choose the account that you are intending to use with the Azure Cloud Shell and enter your password, if necessary. Once entered, the page will prompt you to close the open browser tab or window, and VS Code will continue to authenticate in the background.

You may notice that the URL used to sign in is of the format, [localhost:123456](http://localhost:123456) where the 123456 is a randomly chosen port usually in the 62000 range.

Choosing an account to authenticate as from the Azure Account sign-in page.

This process is the same whether you choose the PowerShell terminal or the Bash terminal. As you can see below, once you have authenticated both terminals become available to you.

PowerShell terminal in the Azure Cloud Shell from within VS Code.
Bash terminal in the Azure Cloud Shell from within VS Code.

Conclusion

Integrating the Azure Cloud Shell into VS Code makes a developer’s job much easier. Quick access to commands as you are developing is important to gathering information and running commands to see the results of those changes without switching between different windows constantly. Use the Azure Cloud Shell within VS Code today and see how much your efficiency can improve!