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)