Open In App

Creating Azure Timer Trigger Function using VScode

Last Updated : 30 Mar, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

Pre-requisite: Azure, Azure Functions

Azure Timer Trigger Functions are a type of Azure Function that runs on a pre-defined schedule. This schedule is defined using a CRON expression, which is a string that specifies when the function should be executed. For example, a CRON expression of “0 0 * * * *” would cause the function to run every hour on the hour. Azure timer trigger functions are commonly used for tasks that need to be performed on a regular schedule, such as sending out reminders or cleaning up old data.

Before getting started, make sure you have the following installed:

  • An Azure account
  • The Azure Functions extension for VSCode
  • The Azure Functions Core Tools

Steps to Create Azure Timer Trigger Function

Step 1: Create a new Azure Functions Project

To create a new Azure Functions project in VSCode, open the command palette and type in “Azure Functions: Create New Project”. This will open up a wizard that will guide you through the process of creating a new project.

Create Project - VScode

 

Select an empty folder in which you want to create the project. 

Step 2: Select a language. We will Select Python language for this article to implement the time trigger function. You can choose any language of your choice.

Select Python Language

 

Step 3: Select an Interpreter for the Project

Select Interpreter

 

Step 4: Select the Timer Trigger template for your project.

Timer Trigger Template

 

Step 5: Give an appropriate name to the timer trigger function. In my case, the name is “Demo-timer-trigger”

Function name

 

Step 6: Enter a CRON expression in order to specify the schedule.

This is the configuration step for your timer trigger function. The configuration is done using a CRON expression, which specifies the schedule on which the function should be triggered.

In Azure, timer trigger functions use a CRON expression to specify when they should run. A CRON expression is a string that consists of six or seven fields separated by whitespace. These fields represent a time schedule, with each field representing a different part of the schedule.

* * * * * *
| | | | | |
| | | | | +--- day of week (0 - 6) (Sunday to Saturday)
| | | | +----- month (1 - 12)
| | | +------- day of month (1 - 31)
| | +--------- hour (0 - 23)
| +----------- minute (0 - 59)
+------------- second (0 - 59)
CRON Expression

 

Step 7: Select the “Add to workspace” option.

Add to workspace

 

Once you follow these steps you will get the default timer trigger template created along with the required files.

Step 8: In order to run the default timer trigger function press the F5 key or go to the Run option and press “Start Debugging“.

Start Debugging

 

Step 9: A prompt will pop up asking “Select Storage Account“. 

Select Storage Account

 

Select the storage account if you have any else you have to create one storage account. Follow this blog to create a new storage account on the Azure Platform. 

Storage Account Selected

 

After selecting an appropriate storage account, the function will start running and should give the output below:

output

 

Once you have written the function code, you can deploy it to Azure by right-clicking on the project in the Explorer pane and selecting “Deploy to Function App”. This will open up a wizard that will guide you through the process of creating a new Function App in Azure and deploying your function to it.


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads