0
0
AzureHow-ToBeginner · 4 min read

How to Use Deployment Slots in Azure for Smooth App Updates

Use deployment slots in Azure App Service to create separate live environments for your app, like staging and production. Deploy your updates to a slot, test them, then swap the slot with production to update your app without downtime.
📐

Syntax

Deployment slots are named environments under your Azure App Service. You create slots like staging or testing alongside production. You deploy your app code to a slot URL, test it, then swap slots to make the new version live.

Key parts:

  • App Service: Your web app hosting service.
  • Slot name: The environment name, e.g., staging.
  • Swap: The action to exchange content and settings between slots.
bash
az webapp deployment slot create --resource-group <resource-group> --name <app-name> --slot <slot-name>
az webapp deployment slot swap --resource-group <resource-group> --name <app-name> --slot <slot-name>
💻

Example

This example shows how to create a staging slot, deploy code to it, test, and then swap it with production.

bash
az webapp deployment slot create --resource-group MyResourceGroup --name MyWebApp --slot staging
az webapp deployment source config-zip --resource-group MyResourceGroup --name MyWebApp --slot staging --src myapp.zip
# Test your app at https://MyWebApp-staging.azurewebsites.net
az webapp deployment slot swap --resource-group MyResourceGroup --name MyWebApp --slot staging
Output
Deployment slot 'staging' created. Deployment package uploaded to 'staging' slot. Slots 'staging' and 'production' swapped successfully.
⚠️

Common Pitfalls

  • Forgetting to configure slot-specific settings can cause issues; use slot-settings to keep secrets or connection strings unique per slot.
  • Swapping slots without testing can cause downtime or errors.
  • Deploying directly to production slot skips testing benefits.
bash
az webapp config appsettings set --resource-group MyResourceGroup --name MyWebApp --slot staging --settings "DB_CONNECTION=staging-db-connection" --slot-settings

# Wrong: Deploying directly to production
az webapp deployment source config-zip --resource-group MyResourceGroup --name MyWebApp --src myapp.zip

# Right: Deploy to staging slot first
az webapp deployment source config-zip --resource-group MyResourceGroup --name MyWebApp --slot staging --src myapp.zip
📊

Quick Reference

CommandPurpose
az webapp deployment slot createCreate a new deployment slot
az webapp deployment source config-zipDeploy app code to a slot
az webapp deployment slot swapSwap two slots to make new code live
az webapp config appsettings set --slot-settingsSet slot-specific app settings

Key Takeaways

Create deployment slots to test app updates safely before going live.
Deploy your app to a non-production slot, test it, then swap with production.
Use slot-specific settings to keep secrets and configs separate per slot.
Avoid deploying directly to production to prevent downtime.
Swapping slots is a zero-downtime way to update your app.