Azure CLI App Service Commands
This section details the Azure Command-Line Interface (CLI) commands for managing Azure App Service resources. Azure App Service is a cloud service for hosting web applications, REST APIs, and mobile back ends. The Azure CLI provides a set of commands to create, configure, and manage App Service resources.
Key Concepts
Before diving into commands, understand these core App Service concepts:
- App Service Plan: Defines the underlying compute resources for your app. It dictates the region, operating system, size, and scale count.
- Web App: The application itself, deployed to an App Service Plan. Can be a web application, API, or mobile backend.
- Deployment Slots: Allow you to manage multiple deployments of your application. Commonly used for staging and production environments.
- Configuration: Settings such as connection strings, app settings, and general application configuration.
Common Commands
Creating an App Service
To create a new web app, you first need an App Service Plan. Here's how to create both:
# Create a resource group (if you don't have one already)
az group create --name myResourceGroup --location "East US"
# Create an App Service Plan (e.g., Free tier)
az appservice plan create --name myAppServicePlan --resource-group myResourceGroup --sku F1 --is-linux
# Create a web app within the plan
az webapp create --name myUniqueAppName --resource-group myResourceGroup --plan myAppServicePlan
Managing Web Apps
Here are some essential commands for managing your web apps:
- List web apps:
az webapp list --resource-group myResourceGroup
az webapp show --name myUniqueAppName --resource-group myResourceGroup
az webapp start --name myUniqueAppName --resource-group myResourceGroup
az webapp stop --name myUniqueAppName --resource-group myResourceGroup
az webapp restart --name myUniqueAppName --resource-group myResourceGroup
az webapp delete --name myUniqueAppName --resource-group myResourceGroup
Deployment Slots
Deployments slots allow for safe deployment and rollback.
- Create a deployment slot:
az webapp deployment slot create --name myUniqueAppName --resource-group myResourceGroup --slot staging
az webapp deployment slot swap --name myUniqueAppName --resource-group myResourceGroup --slot staging --target-slot production
az webapp deployment slot list --name myUniqueAppName --resource-group myResourceGroup
Configuration and Settings
Manage application settings, connection strings, and more.
- Set application settings:
az webapp config appsettings set --name myUniqueAppName --resource-group myResourceGroup --settings MySetting=MyValue AnotherSetting=AnotherValue
az webapp config appsettings list --name myUniqueAppName --resource-group myResourceGroup
az webapp config connection-string set --name myUniqueAppName --resource-group myResourceGroup --settings "AzureSQLConnectionString=Server=tcp:myserver.database.windows.net,1433;..."
az webapp --help.
Deployment
The Azure CLI supports various deployment methods. Here's an example of deploying from a local Git repository:
# Enable local Git deployment
az webapp deployment source config-local-git --name myUniqueAppName --resource-group myResourceGroup
# The command output will provide Git remote URL. Add it to your local Git repo:
# git remote add azure
# Then push your code
# git push azure master
az login before executing these commands.
Refer to the official Azure documentation for more detailed guides and advanced scenarios.