Yes, you can use Azure Functions to send notifications after shutting down a VM. Here's a general approach to achieve this:
1. Azure Function Setup: Create an Azure Function App with a managed identity. This identity should have the necessary permissions to stop the VM and access Azure resources.
2. Stop VM Logic: Use Azure CLI commands within the Azure Function to stop the VM. For example, you can use `az vm stop` to stop the VM and then check its status with `az vm show --query`.
3. Notification Setup: To send notifications, you can integrate the Azure Function with a service like SendGrid for email notifications or use Azure Communication Services. Alternatively, you can trigger a Logic App from the Azure Function to send notifications.
4. Triggering the Function: You can trigger the Azure Function via an HTTP endpoint. This endpoint can be called from your VM or another service to initiate the shutdown process.
5. Alerts: For automatic notifications when a VM is stopped, consider setting up an Activity Log Alert in Azure Monitor. This can trigger an email action group when the VM is deallocated (stopped).
By combining these steps, you can automate the process of stopping a VM and sending notifications using Azure Functions. However, if you prefer a simpler approach, using Azure Monitor Alerts directly might be more straightforward for notification purposes[1][2][7].
Citations:
[1] https://www.reddit.com/r/AZURE/comments/1ana141/azure_function_app_schedule_startstop_vm/
[2] https://stackoverflow.com/questions/74200229/azure-alert-to-notify-when-a-vm-is-stopped
[3] https://carldesouza.com/automatic-shutdown-of-azure-vms/
[4] https://www.reddit.com/r/AZURE/comments/1chjq5u/shutdown_vms_if_not_used_for_some_x_hours/
[5] https://learn.microsoft.com/en-us/azure/virtual-machines/auto-shutdown-vm
[6] https://www.joelverhagen.com/blog/2022/05/azure-functions-on-vmss
[7] https://techcommunity.microsoft.com/blog/startupsatmicrosoftblog/how-to-automatically-shut-down-idle-vms-in-azure/4376055
[8] https://learn.microsoft.com/en-us/azure/azure-functions/start-stop-vms/overview