Madhuri Mereddy
Shell
Azure App Service allows for web apps to be developed and run in Azure without managing infrastructure. All App Services must run in an App Service Plan. App Service Plans can be basic in the Free Tier, or very expensive based on the services they provide.
Selecting an App Service Plan that is too expensive or leaving App Service Plans running after App Services have been deleted are typical problems for organizations using App Services extensively or without experience. Like oversized VMs, App Service Plans can be Right Sized to meet the needs of the workloads running in them.
The playbook should be run on the cadence of a FinOps team’s Inform phase. If excessive App Service Plans cost is detected, use this playbook to identify unused App Service Plans in Azure Subscription(s) and then either delete or scale them down to free tier to lower costs.
Resource cost owners and engineers operating Azure App Services in Subscriptions for hosting their applications may find this playbook useful.
To best use this playbook the following information is needed:
Below are steps to identify, validate and delete the unused App Service Plan (ASP) or scale down to Free Tier using Azure portal or PowerShell commands.
In a mature FinOps practice, the instructions steps can be automated using available automation tooling:
An ASP becomes unused when there are no longer any apps configured in it. To identify and get a list of all unused ASP in your entire tenant or in a specific Subscription or a Resource Group, go to the App Service Plan services page in Azure Portal and filter out all the plans using the column “Apps” set to 0. If you are looking at a subset of Subscriptions or Resource Groups, you may set Subscription/ResourceGroup filters accordingly.
Azure Advisor can also be used to check for unused ASP recommendations.
Note: Execution time varies as further optimization approvals to be confirmed
Once identified, the unused ASPs usage requirement needs to be validated with the Application/Architect team.
App Services applications in a Development or Test environment can often share a single ASP, or use free-tier prior to moving to Production, or more rigorous testing environments. Application/Engineering/Architecture teams should be able to provide support for the needs of the ASP as built.
Action can be determined based on validation of need by the Application team:
If unused ASP are identified/validated and confirmed for deletion, team(s) or individual(s) who manage resources and have the RBAC permissions can follow below instructions to delete unused ASP either from the Azure portal or using PowerShell commands.
In the Essentials pane of ASP in the portal, validate an unused App Service Plan in the portal by checking the “Apps/(Slots)” link as highlighted in the below screenshot which should be 0.
Figure 1: Overview of Azure App Service Plan
Once validated, click on Delete button highlighted to the delete the App Service Plan.
Following Azure PowerShell cmdlets can be used to validate and delete unused ASP
Get number of apps configured in a given App Service plan and confirm its zero (0)
Get-AzAppServicePlan – Follow this Microsoft documentation link for cmdlet details.
For example:
$NumOfSites=(get-azappserviceplan -resourcegroupname "<YourRGName>" -Name "<YourASPName>").NumberOfSites
On successful validation of unused ASP, delete the Azure App Service plan
Remove-AzAppServicePlan – Follow Microsoft documentation link for cmdlet details.
For example:
Remove-AzAppServicePlan -ResourceGroupName "<YourRGName>" -Name "<YourASPName>"
If unused ASP are identified/validated and confirmed to be scaled down, the resource owners can follow below instructions to scale down unused ASP either from the Azure portal or using PowerShell commands.
In the Essentials pane of ASP in the portal, validate the unused App Service Plan in the portal by checking the “Apps/(Slots)” link as highlighted in the screenshot Figure 1 in section 3 above.
Note down the current pricing plan of the ASP and add a new tag with the same. The tag will be useful in scenarios where the unused ASP will be hosting apps again and needs to be scaled back to its original pricing configuration.
To scale down the pricing tier, click on the “Scale Up” on the left pane and then in the resulting screen, select the Free Tier F1 to scale down to free pricing tier or the agreed upon lower pricing tier.
Figure 2: Scaling options for Azure App Service Plans
Following PowerShell cmdlets can be used to validate and scale down unused ASP.
Get number of apps configured in a given App Service plan and confirm it’s zero (0).
Get-AzAppServicePlan – Follow Microsoft documentation link for cmdlet details.
For example:
$NumOfSites=(get-azappserviceplan -resourcegroupname "<YourRGName>" -Name "<YourASPName>").NumberOfSites
Note down the current pricing plan of the ASP and add a new tag with the same. The tag will be useful in scenarios where the unused ASP will be hosting apps again and needs to be scaled back to its original pricing configuration.
Update-aztag – Follow these Microsoft documentation links for cmdlet details or PowerShell help.
For example:
$OrigTier=(Get-AzAppServicePlan -ResourceGroupName "<YourRGName>" -Name "<YourASPName>").Sku.Size $tags = @{“OriginalPricingTier”=$OrigTier} $resource = Get-AzResource -Name “<YourASPName>” -ResourceGroup “<YourRGName>” Update-AzTag -ResourceId $resource.id -Tag $tags -Operation Merge
On successful validation scale down the plan tier to confirmed tier/worker size:
set-Azappserviceplan – Follow this Microsoft documentation link for cmdlet details.
For example:
set-Azappserviceplan -Tier "<YourASPTier>"-resourcegroupname “<YourRGName>" -Name "<YourASPName>" -WorkerSize "<YourASPWorkerSize>”
For Free tier F1, use parameter values -Tier “Free”, -Workersize “Small”
Scale down to Free tier is not available from all ASP pricing tiers.
We’d like to thank the following people for their work on this Playbook:
We’d also like to thank our supporters: Diana Bele and Marcel Paap.