Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Azure Developer CLI (azd) supports Azure App Service deployment slots for apps hosted on App Service. You can define slots in your infrastructure, deploy code to a specific slot, and swap slots when you're ready to promote a release.
Use this approach for staging, blue-green deployments, smoke testing, and rollbacks without adding custom deployment scripts.
Prerequisites
- An
azdproject that deploys a service to Azure App Service. - Infrastructure-as-code that defines your App Service resources in Bicep.
- An App Service plan on Standard (
S1) tier or higher. Free, Shared, and Basic tiers don't support deployment slots.
Define a deployment slot in Bicep
Define your production site as usual, then add a Microsoft.Web/sites/slots resource for each slot you want azd to target.
resource appServicePlan 'Microsoft.Web/serverfarms@2021-03-01' = {
name: 'my-appservice-plan'
location: resourceGroup().location
sku: {
name: 'S1'
tier: 'Standard'
}
}
resource webApp 'Microsoft.Web/sites@2021-03-01' = {
name: 'my-appservice'
location: resourceGroup().location
kind: 'app'
properties: {
serverFarmId: appServicePlan.id
}
}
resource stagingSlot 'Microsoft.Web/sites/slots@2021-03-01' = {
name: '${webApp.name}/staging'
location: webApp.location
properties: {}
}
If you use Azure Verified Modules (AVM), define the web app and deployment slot modules in the same deployment and pass the app name to the slot module.
Deploy to a slot with azd
Run azd up or azd provision and azd deploy as usual.
azd up
On the first deployment, azd deploys to the production site and any slots defined in your infrastructure. After that, if your service has more than one slot, azd deploy prompts you to choose the target slot.
To skip the prompt, set an environment variable for the service you want to deploy. Use the service name from azure.yaml in uppercase.
azd env set AZD_DEPLOY_MYAPI_SLOT_NAME staging
azd deploy myapi
For example, if your service is named web, set AZD_DEPLOY_WEB_SLOT_NAME. This approach is useful for CI/CD because you can set the same environment variable in your pipeline before running azd deploy.
Swap Azure App Service deployment slots
Use the azure.appservice extension to swap slots after validation. If the extension isn't already installed, azd prompts you to install it the first time you run the command.
Run the interactive experience:
azd appservice swap
If only one nonproduction slot exists, azd skips the prompts and swaps directly with production.
For automation, specify the source and destination slots explicitly. Use @main to reference the production slot.
azd appservice swap --src staging --dst @main
azd appservice swap --src @main --dst staging
azd appservice swap --service myapi --src staging --dst @main
Use these patterns to support common release flows:
- Promote a validated staging deployment to production with
--src staging --dst @main. - Roll back by swapping production back into the staging slot with
--src @main --dst staging. - Target a specific App Service-backed service in a multiservice
azdproject with--service.
Recommended deployment slot workflow
- Define one or more App Service deployment slots in your Bicep templates.
- Provision the App Service resources by using
azd provisionorazd up. - Deploy application code to a staging slot by setting
AZD_DEPLOY_<SERVICE_NAME>_SLOT_NAMEor by selecting the slot when prompted. - Validate the staged deployment.
- Run
azd appservice swap --src <slot> --dst @mainto promote the release. - If needed, run the reverse swap to roll back.