Call an azure function whenever an instance is added or removed in my azure virtual scale set

295 views Asked by At

I have a virtual scale set in azure and I want to trigger an azure function whenever an instance is removed or added from virtual scale set. Is there any way I could do this?

1

There are 1 answers

0
Bhargavi Annadevara On

Oh yes, this is possible via Webhooks. Webhooks allow you to route the Azure alert notifications to other systems for post-processing or custom notifications. It's just that the webhook URI must be a valid HTTP or HTTPS endpoint, which in this case could be an Azure Function with a HTTP Trigger.

For newer Virtual Machines created with Resource Manager (Virtual Machine scale sets), you can configure notifications for your scale set's autoscale actions using the Azure Portal, REST API, Resource Manager templates, PowerShell, and CLI.

When using the REST API or Resource Manager template, include the notifications element in your autoscalesettings with the following options:

"notifications": [
      {
        "operation": "Scale",
        "email": {
          "sendToSubscriptionAdministrator": false,
          "sendToSubscriptionCoAdministrators": false,
          "customEmails": [
              "[email protected]",
              "[email protected]"
              ]
        },
        "webhooks": [
          {
            "serviceUri": "https://foo.webhook.example.com?token=abcd1234",
            "properties": {
              "optional_key1": "optional_value1",
              "optional_key2": "optional_value2"
            }
          }
        ]
      }
    ]

where you can configure the serviceUri property with your Function App's endpoint.

The webhook can authenticate using token-based authentication, and includes some metadata in the payload that can be used in further processing.