In this Course, you will learn about Microsoft Azure, one of the main cloud service vendors.
As you saw in the last demo, it's pretty easy to use the portal to create Azure resources but it's definitely not the most efficient way to do it because it requires a lot of pointing and clicking. An alternative is to use the command line. Although it can be more difficult since you have to know the exact names of all the command line options. Once you've mastered it, you can often create and manage resources much more quickly.
In this demo, I'm going to show you how to create a website using Azure App Service. Do you remember when I said that it's possible to use the command line without having to install anything on your desktop? Well, now that you're familiar with the portal, I'll show you how.
You see this icon to the right of the search bar? That's how you start something called the Cloud Shell. It's a very small virtual machine that you can use to run Azure commands. Click on it.
The first time you run Cloud Shell, it'll ask you for permission to create a storage account that the Cloud Shell VM can use. This isn't the first time I've used Cloud Shell, so my storage account is already set up. If you do get a dialogue box asking for permission, then click the option to create a storage account.
Cloud Shell supports both PowerShell and the Bash shell. You can switch between them using this menu. We're going to use the Bash Shell because the commands are simpler. If you're familiar with Linux commands, then it will be especially easy.
First, we need to download the files for a sample website. The command to do that is pretty long, so it's easiest to copy and paste it. You can get it from the read me file in the GitHub repository for this course. You can find a link to the repository at the bottom of the overview tab below this video.
Okay, copy this
git clone command and paste it into the Cloud Shell window. It created a directory (which is the Linux term for folder) called html-docs-hello-world. Change into that directory with the
cd command. I'm just going to use keyboard shortcuts to do the copying and pasting now. Now we can create an Azure App Service Web App using one command. Here it is.
It starts with
az which means it's an Azure command. Then we say
webapp which is the command for Azure App Service. Then
up which means to create the web app using the code in the current directory. Then we say
--location and the name of the region where we want to deploy the web app. I've set it to
westus. Then we say
--name and what we want to call the app. I'm calling it
ca-example, but you'll have to call it something else because the name has to be unique among all of the out service names across all Azure customers. Then we say
--html to tell it that we're creating a static HTML website. Now hit Enter.
That's all you have to do to create a website running on Azure App Service. It'll take a little while to deploy so I'll fast forward.
Okay, it's done. Now we can make sure the website is working by going to this URL. Remember to change this name to the one you used. Great, there's the sample website.
All right, now let's delete the web app, so we don't incur any more charges. In the VM demo, we deleted everything associated with the VM by deleting its resource group. We can do the same thing here but since we didn't specify a resource group name in the command, how do we do that? App Service created a resource group for us. You'll see it in the output from the command. Type
az group delete --name then copy and paste the resource group name from here. Type "y".
While that's getting deleted, I should mention that there are many ways to deploy a web app. For example, both Visual Studio and Visual Studio Code can publish an app directly to Azure App Service without you needing to use the Azure portal or the command line. Once the app is deployed, though, you'll need to use the portal or the CLI to manage it.
And that's it for using the CLI.
A world-leading tech and digital skills organization, we help many of the world’s leading companies to build their tech and digital capabilities via our range of world-class training courses, reskilling bootcamps, work-based learning programs, and apprenticeships. We also create bespoke solutions, blending elements to meet specific client needs.