How To Schedule Tasks In Windows EC2 Instances Or Windows Servers
In this tutorial , We will learn how to automate a process / job or a task in the Windows EC2 Instance using Scheduled tasks.
As like We are running Cron jobs in the Linux Operating system to backup files or to remove older files etc.
The same can be done in the Windows operating systems using Task Scheduler.
For this tutorial , I am going to automate a process to run everyday at 5 PM , The task is to sync all the files from a Folder in the Windows Server to S3 bucket using aws cli.
Creating Tasks Using Task Scheduler
To create a Basic tasks , Login to the Windows EC2 Instance and type Schedule tasks in the Search box.

Clicking that , Will open a New Window which is known as Task Scheduler.
In the Right Hand side , You will see the lists of Actions available , Such as Creating tasks , Importing tasks , Disabling task history , To display all running tasks.

Lets us first understand the usage of task scheduler.
Task scheduler is used to Create , manage and to automate the tasks that the system wants to perform.
You can view the lists of available tasks configured , By clicking Task Scheduler Library in the left pane.
There we can get the detailed information about each tasks , We can modify the tasks at any time as per the requirements.
To Create a new task , On the right side , Under Actions , Choose Create Basic Task
You will be asked to provide a name for the task.

Click Next , Here We have to mention , How often you want the task to be triggered or executed. For instance , Daily

You are provided with various triggers such as weekly , monthly , One time , When log on , When computer starts , Or when specific event is logged.
Click Next , Depending on the trigger you have chosen , You will be asked to provides the details such as Start Time , Recur every , etc.

I have configured the task scheduler to execute the task everyday at 11:55 PM.
Click Next
You should mention the action to be performed , Choose Start a program

Choose Next , And here you should provide a tasks in the form of program / script to the task scheduler.
To Create a script , Go to any folder in the Windows instance ,
Right Click , Click New , Text Document

Give a name for the file and the extension for the file should be .bat (which is known as batch file) , For example , test.bat
Which changing the extension of the file , It will ask for the confirmation , Click Yes
To add commands to the .bat file , Select & Right click the file , Choose Edit
It will open the file and You can add the commands here.
For this tutorial , As I said earlier , I am going to sync all the files from the folder to S3 Bucket.
Here is the command I have used to sync the files to S3 bucket.
aws s3 sync C:\folder\. s3://bucket-name/
After you have added the command , Save and close the file.
Now , Go back to the Task Scheduler
Click Browse , Choose the .bat file you have created.

Click Next , You will the get the summary of the task configured.
and Click Finish.
If you want to run and check the tasks , Choose Task Scheduler Library , Select the task you have created.
In the right side , You will get the Run option , It will start the task. This is the manual way of starting the task in the Task Scheduler.
To check the history of the task , By click History

At any point , If you want to change the properties of the task , Select the task , Right click and Choose properties.
If you want to modify Triggers , Select and Click Edit and make changes as required.
Or If you want to change the batch file itself , You can change it under Actions.
Conclusion
We have learnt how to automate a task or a process in the Windows EC2 Instance or Windows Servers.
Hope you found it helpful , Thanks for reading this article.
Please do check out my other publications.