Spot Instances Eviction Event Handling

Rohit Garg 1 Reputation point
2021-02-18T08:51:36.363+00:00

want to read eviction events from outside the instances at a central place and take action like draining the instance or marking it unhealthy based on event type. What is the right way to do so ? Tried looking into scheduled events but will have to poll it every second and it has non-routable ip which can be used from within the instance.
Azure functions or Logic apps ?

Azure Virtual Machines
Azure Virtual Machines
An Azure service that is used to provision Windows and Linux virtual machines.
8,813 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Amira Bedhiafi 31,421 Reputation points Moderator
    2025-03-22T14:38:35+00:00

    Hello Rohit !

    Thank you for posting on Microsoft Learn.

    You can collect eviction notifications centrally using a custom agent running inside each Spot VM that pushes the event to a centralized Azure Function / Logic App / Event Grid / Event Hub. Here's how:

    You must still check /metadata/scheduledevents locally, there’s no way around that because that metadata endpoint is only available within the VM and is non-routable from outside.

    You can use a lightweight script or agent to:

    • Poll the endpoint (every 1–2 seconds is fine)
    • Detect eviction notice (EventType: Preempt)
    • Push an event to a central location (Azure Function, Event Hub, etc.)
    curl -H Metadata:true "http://169.254.169.254/metadata/scheduledevents?api-version=2020-07-01"
    

    Once the eviction event is detected, forward the payload to a centralized event handler:

    • Azure Function (ideal for light logic, retry, webhook-like behavior)
    • Azure Logic App (if you prefer no-code flows and integrations)
    • Azure Event Hub (for high-throughput event stream)
    • Azure Monitor/Log Analytics (optional for diagnostics)
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.