top of page

Azure Function - Time Trigger

Updated: Mar 14

Author: Sankalp Jain


Azure functions are serverless computing services that enable you to run code on demand in a cost-effective and scalable way. Functions can be triggered by events from a variety of sources, such as Azure Blob storage, Cosmos DB, and Azure Event Grid.


They are an ideal solution for processing data, integrating with other services, and building event-driven applications. They are easy to get started and allow you to focus on your business logic rather than worry about infrastructure management.


The steps that need to be followed to create the Azure function are:


Step 1- We need to log in to the Azure account. Look for the Function App in the Search Resources section in the Navbar.



Step 2 - Once you find the Function App, we will create a new Function App for our project.



Step 3 - To create a new function app, you need to take care of the following fields:

  • Resource Group in which the Function App needs to be created.

  • Unique Function App name.

  • Runtime Stack

  • The region where it needs to be deployed



Step 4 - After you click the Review + Create button, you will see this page where the deployment of your new Function App is shown as completed.



Step 5 - Once the Function App is created, we need to create a new function where we can deploy our code.



Step 6 - While creating the new function, we will be choosing the Deployment Environment as VS Code or a local environment as it provides more flexibility in terms of creating a function.



Step 7 - To create a function locally, first, we need to install the following dependency mentioned in the Azure portal.



Step 8 - I am using VS Code as my code editor. Suppose you are creating Azure Function for the first time locally. You need to install the extension for Azure Function as well.



Step 9 - Once the Azure Function extension has been downloaded, you need to log in to your Azure account where you want to deploy your Azure function. We are creating a new project for our function. Once you start to create a new function, the prompt will ask you for the type of function you want to create. There is a lot of function provided by Azure, but for our use case, we are only creating Azure Time Trigger Function.



Step 10 - While creating the function, it will ask you to enter the CRON expression. The format for creating a CRON Expression is like {second} {minute} {hour} {day} {month} {day of the week}



Step 11 - We have created two Time Trigger Functions for our use case. One is to scrape the factors from the factor table of CWE, and another is to scrape all the contents present in that CWE.



Step 12 - You can add your working python script in the main function of the code of every Trigger. You can find the main function in __init__.py file.



Step 13 - Add all the necessary libraries that need to be downloaded and used to run the function. This requirements file needs to be updated mandatorily without fail to keep the function running without any errors.



Step 14 - You can find the local.setting.json in the directory where we have created our new function. This file is automatically created at the time of the creation of a new project. We need to update the AzureJobsStorage with the connection string. To find the connection string refers to Step 15.



Step 15 - Go back to the storage account in the Azure portal and look for the Access Keys of that storage account. Click on the Show keys button on the top to see the Connection String. Copy and Paste it into the AzureJobsStorage mentioned in Step 14.



Step 16 - A function.json file is also created automatically. You can configure the bindings of a particular function with the help of this file. Currently, it just has the time when this Trigger needs to be fired.



Step 17 - You can run the function by pressing F5 key. Once it starts running, you can see all the dependencies being installed to run the function in the Terminal.



Step 18 - You can see a new file is being created in the container of the storage account every time the trigger is executed successfully.



Step 19 - As our functions are successfully running in the local environment. Now we will be deploying them to the Azure Function App of our account. It will ask for a resource where we need to deploy it.



Step 20 - As we have already created the scrapefuntion Function App. It will ask to overwrite any previous deployment. Just click deploy.



Step 21 - You can see the functions that we have created locally are being deployed to the Function App of our Azure account in the output screen of VS Code.



569 views0 comments

Recent Posts

See All
bottom of page