In this post, I want to show you how to create the infrastructure to host a web application. To do this, you will need to at least create two resources: a web application and an App Service plan. The web application is the resource for which an application runs. The Application Service Plan is the resource that defines the location, size, capacity, and features for which the web application will run.

Prerequisites

  • This tutorial assumes that you already have a Microsoft Azure account configured.
  • You created a Resource Group for these resources and the new ones deployed in this tutorial will join that group. If you want to know how to create a Resource Group, check out this¬†link.

Azure PowerShell Workaround

If you want to know how to install the PowerShell Azure module on your machine, check out this link.

The simplest way to get started is to sign in interactively at the command line.

This cmdlet will bring up a dialog box prompting you for your email address and password associated with your Azure account.
If you have more than one subscription associated with your mail account, you can choose the default subscription. To perform this task, we will use the following commands:

Once you set your default subscription, you’re ready to start.

Set the variables

Here, we define the characteristics of our environment and the resource’s properties.

Create an Application Service Plan

To deploy Web Apps in Azure, you must first have an Apps Service. To create one, you should use the New-AzAppServicePlan cmdlet with the following syntax.

The -Tier parameter allows the following values: Free, Basic, Shared, Standard, Premium, PremiumV2, PremiumContainer, and Isolated.

Create a Web Application

Once you have an Apps Service, you are ready to create a Web App, for this you should use the New-AzWebApp cmdlet with the following syntax.

At the end of the creation process, you can use the following command to obtain the most relevant data of the Web App created.

Get-AzWebApp

Create a deployment slot

If you have a Standard service plan or higher, you can use deployment slots. To create a new deployment slot, you should use the New-AzWebAppSlot cmdlet as shown below.

Important: All the slots that are created in the same service plan, including the “Production” slot share resources. For this reason, it is advisable to use an independent services plan in production environments.

New-AzWebAppSlot

Clone an existing deployment slot

Another way to create a new deployment slot is to clone an existing slot. In the following example, I will create a new slot using the production slot as the source.

Azure WebApps

Swap deployment slots

if you want to swap the contents of one slot with another. You should use the Swap-AzWebAppSlot cmdlet with the following syntax.

Remove a deployment slot

To remove a deployment slot, use the Remove-AzWebAppSlot cmdlet with the following syntax.

Remove a Web Application

To remove an Azure Web App, you should use the Remove-AzWebApp cmdlet This cmdlet, by default, also removes all slots and metrics.

Remove an Application Service plan

and finally, if you want to delete the service plan, you should use the Remove-AzAppServicePlan cmdlet with the following syntax.

Azure CLI Workaround

In this case, we will use Azure Cloud Shell, a browser-based shell built into Azure Portal. This allows us to use the Azure command-line tools (Azure CLI and Azure PowerShell) directly from a browser. If you want to know more about Azure Cloud Shell, check out this link

Create an Application Service Plan

To deploy a Web app in Azure, you must first have an Apps Service. To create one, you should use the following command.

The -sku parameter allows the following values: B1, B2, B3, D1, F1, FREE, I1, I2, I3, P1V2, P2V2, P3V2, PC2, PC3, PC4, S1, S2, S3, SHARED.

Azure WebApps

Create a Web Application

Once you have an Apps Service, you are ready to create a Web Apps, for this you should use the following command.

Azure WebApps

At the end of the creation process, you can use the following command to obtain the most relevant data of the Web App created.

Azure WebApps

Create a deployment slot

If you have a Standard service plan or higher, you can use deployment slots. To create a new deployment slot, you should use the following command.

Important: All the slots that are created in the same service plan, including the “Production” slot share resources. For this reason, it is advisable to use an independent services plan in production environments.

Clone an existing deployment slot

Another way to create a new deployment slot is to clone an existing slot. In the following example, I will create a new slot using the production slot as the source.

Azure WebApps

Swap deployment slots

If you want to swap the contents of one slot with another. You should use the following command.

Remove a deployment slot

To remove a deployment slot, use the following command.

Remove a web application

If instead, you want to remove the Azure web application, you must use the following command.

Remove an Application Service plan

And finally, if you want to delete the service plan, you should use the following command, this command will ask for confirmation to continue with the removal of the resource.

Azure WebApps

Thanks for reading my post. I hope you find it useful.
If you want to know more about Azure Web Apps, check out this link: https://docs.microsoft.com/en-us/azure/app-service/overview