The cloud shell in Azure is for you to interact with services in both a command-line and development approach. It is a browser-based shell that allows you to run commands (PowerShell, Bash, Python, etc) and run code/scripts without having to install additional software to a computer. Most of the tools that an Azure engineer or DevOps engineer will work with are built-in.
Most Azure users know cloud shell as that button in the portal on the top right that looks like a shell sign.
Accessing the cloud shell from the portal is one method, but there is a much more rich and efficient approach, the cloud shell portal.
To follow along with this post, you will need:
- Azure account. If you don't have one, create a 30-day free trial here.
- PowerShell. If you are on Windows 10, Windows PowerShell works fine. If you are on OS X, Linux, or another distro, you will need to install PowerShell core which you can find here.
Creating a Storage Account for Cloud Shell
For cloud shell to store and run code, it needs to store the code somewhere. The way to store code in cloud shell is with a storage account.
To create a storage account, please open up a terminal and run the PowerShell code below after you put in the appropriate parameters for your environment.
param( [string]$storageAccountName, [string]$resourceGroup, [string]$location ) az storage account create -n $storageAccountName -g $resourceGroup -l $location --sku Standard_LRS
After running the PowerShell code, an output similar to the screenshot below will be shown. The storage account has been created and it's time to go to the Azure portal.
Accessing the Cloud Shell
In the previous section you learned the prerequisite for cloud shell and how to create said prerequisite, a storage account. Now it's time to set up cloud shell.
Open up the Azure portal and sign in if you aren't already.
Click on the cloud shell icon as shown in the screenshot below.
Creating a Cloud Shell Storage Account
A screen will show up on the bottom of the Azure portal like in the screenshot below.
Click on Show advanced settings to choose an existing storage account.
For the advanced option, you will need to choose:
- An existing resource group. For example, the resource group that you used to create the storage account.
- The storage account you created.
- Azure subscription
- Region for cloud shell
- New file share for within your cloud shell.
Choose these values and click the blue Create storage button.
Please note that my values will be different from what you use in the Azure subscription you are using.
The cloud shell environment will start initiating.
Cloud shell is now active and usable!
Using Cloud Shell
In the previous section you learned how to initiate a cloud shell instance to use in an Azure environment. You will now learn how to interact with the cloud shell outside of the Azure portal.
Using the Shell in the Cloud
Go to this link and a new tab in the web browser will open for the cloud shell.
The key difference from using the shell in a web browser to using the shell from the portal is that the web browser gives you way more real estate.
Shell in the web browser gives you the same features that the shell in the Azure portal gives you. For example, you can still switch between PowerShell and Bash or change your fonts.
Visual Studio Code (VS Code) in Cloud Shell
One of the coolest features is Visual Studio Code at your fingertips. By simply typing
code . on the terminal, VS Code will open.
The great part about this is you now have one location to write code without having to download any tools. Let's think of an example.
Say you're traveling and your laptop breaks. What do you do? Well, find a store that hopefully has a laptop for you to buy. Chances are your organization has a policy in place that states you can only run their software on specific machines that have policies enabled for security purposes. The other big part is, what machine are you going to buy? Are you going to fork out $2,000 dollars for a beefy machine to run your software? If you do, is the company going to reimburse you?
With cloud shell, this goes away. You can log into cloud shell from any computer and start writing code. This saves you time, productivity, and money.
In this blog post you learned about how to create a cloud shell instance in Azure, interact with the cloud shell, and move out of the Azure portal to use the cloud shell in a web browser. You then learned how to use VS Code in the cloud shell and some benefits it gives you.