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:
I then perform a Slot Swap operation from the Azure Portal:
app.azurewebsites.net
and suddenly starts receiving requests for app-staging.azurewebsites.net
.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".
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.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.
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:
Is there any way to get this information without using my SlotName.txt
trick?
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”.
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.
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.
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.
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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With