Using App Service Plan in Azure
02 Aug 2020 - Sanjeev
Skills Measured
- Create an Azure App Service Web App
- Enable diagnostics logging
- Deploy code to a web app
- Configure web app settings including SSL, API, and connection strings
- 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.
- Provision an App Service Plan and create a WebApp instance
- Deploy the code from a source code repository
- Update the code to use SQL Server database
- Add rules for auto scaling
- 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.
ensure it run by executing the command dotnet run
We have multiple options for deploying this application to Azure. Below picture summarizes the current options.
Below are the steps to be followed for deploying using zipdeploy. Execute the command dotnet publish -c Release -o out
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 *
Execute command az webapp deployment source config-zip --src site.zip
from Azure Shell
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!