Using App Service Plan in Azure

02 Aug 2020 - Sanjeev

Skills Measured

  1. Create an Azure App Service Web App
  2. Enable diagnostics logging
  3. Deploy code to a web app
  4. Configure web app settings including SSL, API, and connection strings
  5. Implement autoscaling rules, including scheduled autoscaling, and scaling by operational or system metrics

We will do the following to understand different concepts involved to learn the skill set being measured.

  1. Provision an App Service Plan and create a WebApp instance
  2. Deploy the code from a source code repository
  3. Update the code to use SQL Server database
  4. Add rules for auto scaling
  5. Add diagnostic logging to the application

Provision an App Service Plan and create a WebApp instance

Navigate to Azure Shell and sign-in. Execute below commands to create an app service and web app

  
    randomNumber=$RANDOM 
    resourcegroupName=learnAppservice$randomNumber
    az configure --defaults location=eastus
    az configure --defaults group=$resourcegroupName
    az group create --name $resourcegroupName
    az appservice plan create --name appservice$randomNumber --sku Free
    az webapp create --name webapp$randomNumber -p appService$randomNumber --query defaultHostName
  

Above script when run sequentially will create a app service plan and web app.

Deploy the code from a source code repository

Create a working directory to host an WebApi application using command mkdir webapi4appservice. Make that as the current working directory by navigating to that newly created directory cd webapi4appservice. Execute the command dotnet new webapi to create a new WebApi project.

New WebApi project

ensure it run by executing the command dotnet run

Run the application

We have multiple options for deploying this application to Azure. Below picture summarizes the current options.

App Service deployment options

Below are the steps to be followed for deploying using zipdeploy. Execute the command dotnet publish -c Release -o out

Publish the application

change the working directory to out by executing the command cd out. zip the content of out folder using the command zip -r site.zip *

Zip up out directory

Execute command az webapp deployment source config-zip --src site.zip from Azure Shell

Deploy

Verify the application is deployed by browsing to one of the supported api end points. In this case https://<web app name>.azurewebsites.net/api/Values

Update the code to use SQL Server database

References



Do let me know if you have any clarification/suggestion on this post. I will be happy to know your feedback!