ONE OF THE INCESSANT THINGS WHEN WE USE CLOUD PROVIDERS, IT’S HOW TO HAVE THE BIGGEST EFFICIENCY WITH OUR RESOURCES. IF YOU HAVE AZURE VIRTUAL MACHINES, FOR EXAMPLE, REDUCE THE TIME OF NON-PRODUCTION ENVIRONMENTS STAYS TURNED ON TO 12 HOURS AT WEEKDAYS CAN REDUCE YOUR BILL BY 67%.
Save Money with Azure: Handling your resources with Azure Functions
--
In fact, when a VM is created, there is an option for shutdown within the scheduled time, but it’s a bit limited, due to nonexistence of an option to startup the VMs, nor the option to do this for dependent VMs as a Domain Controller that should be online when the other VMs start.
A good, simple, and cheaper solution for this, is to use an Azure Function to startup and shutdown the Virtual Machines. So let’s see how we can do it!
What you will need:
- Azure Account
- Visual Studio Code
- VS Code — Azure Functions Plugin
- An Azure Virtual Machine
Preparing the Virtual Machine
Now we need to create a beacon in the VMs that we need to shutdown/startup. For this function, we’ll use a tag shutdownDaily
with the value true.
Later we will filter the VMs with this tag and shut it down in the function script.
Creating the shutdown function.
Open the Visual Studio Code, and create a new Powershell Function:
Select the Timer Function option and give a name to the function:
Now we need to define how often the function will be executed. Here we will execute every day at 7 PM.
The Azure Functions use cron expression to define the frequency. (You can have…