Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get the "real" Azure App Service slot instance name?

I'd like to know how I can get a unique identifier for the "slot instance" that an Azure App Service slot has loaded into it.

Note that I am not referring to the name of the slot.

For example:

  • My Azure App Service has two slots named "App" (Production) and "App-Staging" (Staging).
  • I then deploy version 1 of my project to the "App" slot.
  • I then deploy version 2 of my project to the "App-Staging" slot.
  • I then perform a Slot Swap operation from the Azure Portal:

    • Both instances of my app are running simultaneously (imagine they run in a container of some kind).
    • Both "containers" are immediately "detached" from their associated slot while still running.
    • Both "containers" are then immediately re-attached to the opposing slot.
      • i.e. version 1 stops receiving HTTP requests for app.azurewebsites.net and suddenly starts receiving requests for app-staging.azurewebsites.net.
      • and version 2 stops receiving HTTP requests for app-staging.azurewebsites.net and suddenly starts receiving requests for app.azurewebsites.net.
  • In order to investigate some issues I was having, I created a text file at D:\home\SlotName.txt. In the "App" slot I entered "SlotA" and in the "App-Staging" slot I entered "SlotB".

  • This SlotName.txt moves with the application instance, and allows my application to detect which filesystem or "container" instance it's living in - and this doesn't change when a slot-swap is performed.
  • I find this information essential when trying to uniquely identify deployments or when investigating logging continuity issues (as the staging slot won't be logging production data, for example).
  • However, my SlotName.txt file seems like a hack - but I can't see any information in the Environment Variables for my app's instance that reveals the same information.
    • Environment variables do reveal the slot name, e.g. "App" and "App-Staging" which is mutable - of course, but it doesn't uniquely identify the "container" or filesystem instance that the app is deployed into.

Here's the two Kudu Environment pages from the Production and Staging slots - notice that the values are either identical (like Machine name), slot-specific, or refer to the deployed application code and none of them refer to the filesystem / container instance they live in:

enter image description here

Is there any way to get this information without using my SlotName.txt trick?

like image 396
Dai Avatar asked Oct 06 '19 06:10

Dai


People also ask

What is the name of the default Azure App Service deployment slot?

So you need a testing environment that's as close as possible to your production environment. App Service has a great solution. It's called a deployment slot. By default, an app has one deployment slot called “Production”.

What is Azure App Service slot?

Azure Functions deployment slots allow your function app to run different instances called "slots". Slots are different environments exposed via a publicly available endpoint. One app instance is always mapped to the production slot, and you can swap instances assigned to a slot on demand.

What is app service name in Azure?

Azure App Service is an HTTP-based service for hosting web applications, REST APIs, and mobile back ends. You can develop in your favorite language, be it . NET, . NET Core, Java, Ruby, Node. js, PHP, or Python.

How do I find my Azure App Service Code?

FTP into Azure App ServiceThe app service dashboard in the Azure Portal. Next, you need to download the publish profile. The publish profile is going to contain all of the credentials needed for you to FTP into the app service and download your source code.


1 Answers

The answer hiding right under my nose - and different terminology.

What I was calling a "slot instance name" is actually referred to as a "Deployment Id" (I know this is an overloaded term as it's also used in the context of Azure's (now legacy) "Cloud Services" PaaS too).

This information is visible in the Kudu environment page and is also an exposed as an environment-variable: WEBSITE_DEPLOYMENT_ID.

The WEBSITE_DEPLOYMENT_ID value is of the form {SiteName}[__{Random}], with the __{Random} prefix omitted for the first deployment space.

If you look closely at the screenshot I posted, you'll notice the left-hand screenshot has the site-slot-name Site1__e928 whereas the right-hand screenshot is of the "first" slot-space and so its name is just Site1.

It is unfortunate that this information is not documented by Microsoft publicly - at least so far as Google can see (searching for the term right now yields zero useful relevant results):

Mystery solved!

like image 76
Dai Avatar answered Jan 14 '23 13:01

Dai