How can Azure's VM (spot / termination) events be delivered to a webhook

Vaibhav Gupta 0 Reputation points
2023-08-23T04:26:05.6866667+00:00

Is there any method apart from Scheduled Events, in which my eventGrid topic can receive the VM events such as its termination or Spot VM evictions events, and thereon, my subscriber can listen to those events and act accordingly?

AWS has a mechanism in which EC2 instances events are being delivered to EventBridge in real-time and based on rules, those events can be filtered and sent to targets such as SNS topic.

I am aware of the Scheduled Events service of Azure VM's but in that case I will have to poll inside the VM each second to know the events and as actions to be taken are based on such events, this seem to be risky in case of abrupt machine failure etc.

Also as per documentation https://learn.microsoft.com/en-gb/azure/virtual-machines/linux/scheduled-events#scope,

Scheduled events are delivered to and can be acknowledged by:

  • Standalone Virtual Machines.
  • All the VMs in an Azure cloud service (classic).
  • All the VMs in an availability set.
  • All the VMs in a scale set placement group.

My use case involves launching multiple VM in an availability zone and not in Scale set. Hence how can i setup a one or two machine in a group that can receive the events for all other VM's

Azure Virtual Machines
Azure Virtual Machines
An Azure service that is used to provision Windows and Linux virtual machines.
7,157 questions
Azure Logic Apps
Azure Logic Apps
An Azure service that automates the access and use of data across clouds without writing code.
2,855 questions
Azure Event Grid
Azure Event Grid
An Azure event routing service designed for high availability, consistent performance, and dynamic scale.
318 questions
{count} votes

1 answer

Sort by: Most helpful
  1. vipullag-MSFT 24,206 Reputation points Microsoft Employee
    2023-08-30T09:52:14.95+00:00

    Hello Vaibhav Gupta

    Azure Event Grid is a fully-managed event routing service that enables you to build event-driven applications with ease. You can use Azure Event Grid to route events from any source to any destination, and you can use it to build reactive applications that respond to events in real-time.

    Regarding your question, Azure Event Grid can be used to receive VM events such as termination or Spot VM evictions events. You can create an Event Grid subscription to listen to these events and take appropriate actions based on the events received**.**

    However, unlike AWS, Azure does not have a built-in mechanism to deliver VM events to Event Grid in real-time. You can use Azure Monitor to collect VM events and send them to Event Grid, but this is not a real-time solution.

    Regarding your concern about polling inside the VM each second to know the events, you can use Azure Event Grid's retry policy to ensure that events are not lost in case of abrupt machine failure. Azure Event Grid will retry sending the event to the subscriber for a configurable amount of time before giving up.

    Regarding your use case of launching multiple VMs in an availability zone, you can create an Event Grid subscription to listen to events from all the VMs in the availability zone. You can use the same approach as you would for a scale set placement group.

    Hope this helps.