This article shows you how to schedule start and stop times for an Azure virtual machine. This way for example, you can schedule the VM to run only during open hours and shutdown during off hours and the weekends.
The method we'll be using to schedule the stop and start times is via an Azure Logic app, which is also very inexpensive for our use-case.
Configure the Start Logic App
First, navigate to the Logic apps service.
Once inside the service, click + Add to create a new Logic app.
Here, we will create the Logic app used to start your virtual machine at specific times.
On the Basics tab, fill out information such as the
Logic App name and
Region. If possible, it is recommended to create the Logic app in the same environment as your virtual machine.
Since the Logic app will have a very limited number of runs per day, it is best to use the
Enabling or disabling
Zone redundancy is up to your own discretion.
After filling out all the relevant fields, click Review + create, then click Create.
After the deployment has created, click Go to resource.
Once inside your Logic app, on the left side-bar menu, go to
Logic app designer.
Here you will see a list of common triggers. Click on
To start your virtual machine on specific days, change the
Frequency to Week and set the
Interval to 1 so the trigger will run once a week on your specified days.
Add new parameters for
On these days,
At these hours and
At these minutes. Configure these parameters to your own specifications.
In my example, the Preview shows the virtual machine will start at 7AM Eastern Time on Monday-Friday.
Now that your start schedule has been created, you will need to add a New step to start the virtual machine.
Under Choose an operation, search for and select
Under Actions, select
Start virtual machine.
Fill out the information for the
Resource Group and
After you've filled out all the information for both the Recurrence Trigger and Start virtual machine Action, in the top left of the Logic app designer, click Save.
To have your Logic app go into action, you'll need to click Run Trigger.
Note: You may need to click Run Trigger again if you Save any changes to your Logic app in the future.
Configure the Stop Logic App
The final step would be to create a new Logic app for scheduling the stop times for the virtual machine.
Follow the same steps as before for creating a new Logic app and configuring the Recurrence Trigger, but change the At these hours parameter so it stops at your desired time.
Make sure to select
Deallocate virtual machine and not
Power off virtual machine. If you only power off the virtual machine, not deallocate it, then you'll still be charged as if the VM is running.
Using these two Logic apps, my virtual machine,
Demo, will only be running from 7AM - 8PM EST on Monday - Friday, saving over
100 hours of runtime charges.