Postponing Azure VM Auto-Shutdown From Your iPhone

I normally use Azure Devtest Labs for managing the remote environments I work in, but now and then I have to set up standalone VMs outside a lab, and the first thing I do in the case of a cost-intensive resource (like, say, a GPU-enabled machine where I’m training a neural network1) is set up an auto-shutdown timer (usually for around dinner time).

This is supported on all VMs now – automatic power-on isn’t yet supported outside Devtest Labs, which is sad, but I’m hoping it will surface some time in the future.

The one catch with this approach is that I often need to keep working for a while, and I’m invariably not logged in to the right subscription (or even to the portal itself) when auto-shutdown kicks in, so I’m often caught by surprise (nearly always when I’m actually logged in directly to the machine).

Going over to the portal in a hurry and trying to find the right machine amidst hundreds of resources is a major pain and completely breaks my flow, so in order to avoid chagrin and interruptions I’ve been looking into ways to have a bit more control over auto-shutdown.

That led me to investigate Azure infrastructure web hooks – you can define hooks for metrics alerts, and as it happens Devtest Labs also has an auto-shutdown hook. After a little searching and asking around (because it’s still somewhat hard to find this in the docs outside the context of Devtest Labs), I figured out that the Schedules > Auto-shutdown web hook available for any VM works exactly the same as the ones in Devtest Labs).

So I went over to Microsoft Flow, logged in and created a new flow with a Request node and a Send me a mobile notification node, like so:

Can't get any simpler, really.

To provide the required field bindings for the data sent as part of the web hook call, I pasted in to the Request input box the following schema:

{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "properties": {
    "delayUrl120": {
      "type": "string"
    },
    "delayUrl60": {
      "type": "string"
    },
    "eventType": {
      "type": "string"
    },
    "guid": {
      "type": "string"
    },
    "labName": {
      "type": "string"
    },
    "owner": {
      "type": "string"
    },
    "resourceGroupName": {
      "type": "string"
    },
    "skipUrl": {
      "type": "string"
    },
    "subscriptionId": {
      "type": "string"
    },
    "text": {
      "type": "string"
    },
    "vmName": {
      "type": "string"
    }
  },
  "required": [
    "skipUrl",
    "delayUrl60",
    "delayUrl120",
    "vmName",
    "guid",
    "owner",
    "eventType",
    "text",
    "subscriptionId",
    "resourceGroupName",
    "labName"
  ],
  "type": "object"
}

…and I then added the delayUrl60 link as the notification link.

This lets me conveniently postpone shutdown for an hour without having to log in to the portal (or anywhere else) – I just do it straight from my iPhone in a couple of taps (first the notification and then the link inside the Flow app), which is quick and easy enough to not break my flow.

A minor thing, I know, but so useful that I thought it needed more exposure.


Update: Here’s what it looks like on the phone. And yes, that’s a Douglas Adams reference:

All it does is compute "42" millions of times a second.

  1. I haven’t written anything about the deep learning stuff I’ve been doing (just like I haven’t blogged about Kubernetes and other container-related stuff), but that might change in the future – I’ve been sticking to my Disclaimer, but I realize that there’s a lot I can actually write about, once I find the time to do it properly. ↩︎


See Also: