Azure Static Website Deployment Slots

Posted onby admin

The web application and deployment slots are created within the same environment (This is also the case when you create a Azure Web App within the same App Service Plan). This means resources between the two instances are shared, So if you want to do a stress test on pre-production you are certain that it will effect the performance of the. Azure Deployment Slots is a feature that allows Web Apps, API Apps and Function Apps to run different instances of their application at the same time (known as slots). Slots are exposed via a publicly available endpoint.

Sponsored By

I've got a lot of production web sites running in Azure right now. Some are for small side projects and some are larger like the sites for the Hanselminutes Podcast and This Developer's Life. I like Web Apps/Sites (which is Platform as a Service) rather than Virtual Machines (Infrastructure as a Service) because I don't like thinking about the underlying operating system if I can avoid it. I like to be able to scale the site up (faster, bigger) or out (more machines in the farm) with a slider bar.

In fact, there's some other more advanced and useful features that Azure Web Apps have that keep me using Web Apps almost exclusively.

I'll use a little site I made called KeysLeft.com that tells you how many keystrokes are left in your hands before you die. Think of it as a productivity awareness tool.

First, I'll add a Deployment Slot to my existing Git-deployed Web App. The source for KeysLeft lives in GitHub here. When I check-in a change it's automatically deployed. But what if I wanted to have a staging branch and automatically deploy to a staging.keysleft.com first? If it works out, then move it to production by swapping sites. That'd be sweet.

Staging Slots for Azure Web Apps

You can see here my main KeysLeft web app has a Staging 'side car' app that is totally separate but logically related/adjacent to production. Notice the 'swap' button in the toolbar. Love it.

This Web App has its configuration copied from the main one, and I can setup Continuous Deployment to pull from a different branch, like 'staging' for example. The name of the deployment slot becomes a suffix, so keysleft-staging.azurewebsites.net unless you set up a custom CNAME like staging.keysleft.com. You can have up to 4 deployment slots in addition to production (so dev, test, staging, whatever, production) on Standard Web Apps.

A/B Testing for Azure Web Apps

Once I've got a slot or two set up and running a version of my app, I can do A/B testing if I'd like. I can set up a feature that was called 'Testing in Production' and is now 'Traffic Routing' and tell Azure what percentage of traffic goes to prod and what goes to staging. Of course, you have to be sure to write your application so such that authentication and session is managed however is appropriate, especially if you'd like the user to have a seamless experience.

Here I've got 10% of the traffic going to staging, seamlessly, and the other 90% is going to production. I can make a small change (background color for example) and then hit the main site over and over and see the occasional (10% of course) request being routed to the staging slot. You can configure this static routing however you'd like.

Then I could hook up Application Insights or New Relic or some other event/diagnostics system and measure the difference in user reaction between features that changed.

Deployment slots azure web app

Advanced Testing in Production

Made it this far? Then you're in for a treat. Static routing is cool, to be clear, but scripting a more dynamic experience is even more interesting. Galin Iliev, one of the developers of this feature, gave me this Powershell script to show off more powerful stuff.

First, you can use PowerShell to manage this stuff. You can change routing values and ramp up or ramp down. For example, here we start at 10% and change it by 5 every 10 minutes.

But! What if you could write code to actually make the decision to continue or fall back dynamically? You can add a callback URL and a Site Extension called the 'TiP Callback Extension.'

The Site Extension (and all Site Extensions for that matter) is just a little sidecar Web API. This callback gets a small POST when it's time to make a decision, and you decide what to do based on HTTP-related context that was passed in and then return a ChangeDirectionResult object as JSON. You can adjust traffic dynamically, you can adjust traffic when doing a deployment, do a slow, measured roll out, or back off if you detect issues.

NOTE: The ChangeDescisionCallbackUrl and this code below is totally optional (so don't stress) but it's super powerful. You can just do static routing, you can do basic scripted dynamic traffic routing, or you can have make a decision callback URL. So the choice is yours.

You can check out the code by visiting yoursite.scm.azurewebsites.net after installing the TiP callback site extension and look at the Site Extensions folder. That said, here is the general idea.

Azure Static Website Deployment Slots Free

Here's the object you return. It's just a class with two ints, but this is super-annotated.

Azure Static Website Deployment Slots Software

All this stuff is included in Standard Azure Web Apps so if you're using Standard apps (I have 19 websites running in my one Standard plan) then you already have this feature and it's included in the price. Pretty cool.

Related Links

  • Video: Intro to Testing in Production
  • Video: Scripting Testing in Production and Traffic Routing
  • Video: Azure WebSites - Deployment Slots for Staging Sites

Sponsor: Big thanks to Infragistics for sponsoring the feed this week. Responsive web design on any browser, any platform and any device with Infragistics jQuery/HTML5 Controls. Get super-charged performance with the world’s fastest HTML5 Grid - Download for free now!

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.


AboutNewsletter

Azure Tips and Tricks Videos are NOW Available! : Get all the goodness of Azure Tips and Tricks in video form. Read more about it here

Intro

Most folks aren’t aware of how powerful the Azure platform really is. As I’ve been presenting topics on Azure, I’ve had many people say, “How did you do that?” So I’ll be documenting my tips and tricks for Azure in these posts.

The Complete List of Azure Tips and Tricks

This post was brought to you by Lohith (kashyapa).

Slots

What are Deployment Slots?

Deployment Slots are a feature of Azure App Service. They actually are live apps with their own hostnames. You can create different slots for your application (for e.g. Dev, Test or Stage). The Production slot is the slot where your live app resides. With deploymet slots, you can validate app changes in staging before swapping it with your production slot. You can read more about deployment slots here.

Pre-Requisites

  • Microsoft Azure Subscription (Sign up for free)
  • Microsoft Azure CLI (Install from here)

Log in to Azure

Before executing any Azure CLI commands, you will need to login first.

  • Open Command Prompt or a Powershell session
  • Enter following command:

az login

The command will prompt you to log in with an authentication code via a website.

Listing Deployment Slots

To list deployment slots in an Azure App Service, execute the following command:

az webapp deployment slot list -n 'web app name' -g 'resource group name'

Creating Deployment Slot

To create a new deployment slot in an Azure App Service, execute the following command:

az webapp deployment slot create -n 'web app name' -g 'resource group name' -s 'deployment slot name'

Swapping Deployment Slot

Azure App Service Deployment Slots

To swap a deployment slot in an Azure App Service, execute the following command:

az webapp deployment slot swap -n 'web app name' -g 'resource group name' -s 'source slot name' --target-slot 'target slot'

Deleting a Deployment Slot

To delete a deployment slot in an Azpp Service, execute the following command:

Websites

az webapp deployment slot create -n 'web app name' -g 'resource group name' -s 'deployment slot name'

Conclusion

Although Azure portal is a great way to perform most of the Azure related actions, sometimes using the CLI is the easiest. With this tip, we saw how listing/creating/swapping/ deleting deployment slots is just a one line command using the Azure CLI. Hope this helps.

Want more Azure Tips and Tricks?

If you’d like to learn more Azure Tips and Tricks, then follow me on twitter or stay tuned to this blog! I’d also love to hear your tips and tricks for working in Azure, just leave a comment below.