How To Create Azure Functions Time Trigger From Visual Studio 2019

How To Create Azure Functions Time Trigger From Visual Studio 2019

In this Azure tutorial, we will discuss How To Create Azure Functions Time Trigger From Visual Studio 2019. Along with this, we will also discuss a few other topics below.

  • How To Schedule Azure Functions
  • How To Deploy Azure Functions Time Trigger From Visual Studio 2019
  • Create Blob Trigger Azure Function In Visual Studio
  • Deploy Blob Trigger Azure Function From Visual Studio 2019

How To Create Azure Functions Time Trigger From Visual Studio 2019

Well, here we will discuss How To Create And Deploy Azure Functions Time Trigger From Visual Studio 2019. Before we start discussing How to deploy the Azure functions timer trigger from Visual Studio 2019, we will discuss How To Create Azure Functions Time Trigger From Visual Studio 2019.

Before starting the actual development, we should know the Prerequisites

Prerequisites

  • We need an Azure Account or Azure Subscription. Don’t have an Azure Account till now? no worries, create an Azure Free Account now.
  • If you don’t have Visual Studio 2019 installed in your machine, install Visual Studio 2019 now. Along with Visual Studio 2019, you need to install the Azure development workload.
  • We need Updated Azure Function tools
  • You need an Azure Storage Account. If you don’t have an Azure Storage Account till now, create an Azure Storage Account now.

How To Schedule Azure Functions

Well, now we are ready for the development activities with all the Prerequisites needed. Let’s start the creating the Azure Function Project.

Now from your local machine, Open the Visual Studio 2019 and click on the Create a New Project button. On the Create a new project window, select the Azure Functions template and then click on the Next button.

Develop And Deploy Azure Function Time Trigger Using Visual Studio

You need to provide the below details in the below window

  • Project name: Provide the Azure Function Project name
  • Location: You need to choose a location for your Azure Function Project.
  • Solution: Choose to Create new solution

Then, click on the Create button.

How To Create Azure Functions Time Trigger From Visual Studio 2019

Now, this step is very important, We will have to choose a trigger for our Azure Functions. The role of the trigger is to invoke the Azure Function.

Make sure to choose the Timer Trigger as the template and then provide the below details

Storage Account (AzureWebStorage): choose the Storage Emulator option here.

Schedule: You can keep the CORN expression 0*/5**** as it is, this means the timer trigger Azure Function will execute on each 5 minutes interval of time. If You will change it to 0*/3****, then the Azure Function will execute on each 3 minutes interval of time. Decide based on your business requirement. Check out more details on the CORN expression now.

Finally, click on the Create button to create the timer trigger Azure Function.

Create Azure Functions Time Trigger From Visual Studio 2019

Now you can able to see below, The Timer trigger Azure Function project created successfully with out any issue

Create Azure Functions Time Trigger in Visual Studio 2019

Below is the Timer trigger Azure Function Code

using System;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Host;
using Microsoft.Extensions.Logging;

namespace TimeTriggerAzureFunction
{
    public static class Function1
    {
        [FunctionName("mytimertriggerfunction")]
        public static void Run([TimerTrigger("0 */5 * * * *")]TimerInfo myTimer, ILogger log)
        {
            log.LogInformation($"C# Timer trigger function executed at: {DateTime.Now}");
        }
    }
}

You can see it here

How To develop Azure Functions Time Trigger From Visual Studio 2019

This is How To Create Azure Functions Time Trigger From Visual Studio 2019. Now the next is we will discuss How To Deploy Azure Functions Time Trigger From Visual Studio 2019.

How To Deploy Azure Functions Time Trigger From Visual Studio 2019

Follow the below steps to Publish Azure Functions Time Trigger From Visual Studio 2019.

Right click on the Azure Functions Time Trigger project and click on the Publish button

azure function timer trigger visual studio

Click on the Azure Functions Consumption Plan, select the Create New option, and then click on the Create Profile button.

Deploy Azure Functions Time Trigger From Visual Studio 2019

Provide the below details as high lighted

  • Name: Provide the name for the Function App
  • Subscription: Choose your correct subscription
  • Resource group: You can choose your existing resource group or you can click on the New button to create a new Resource Group.
  • Location: Choose a location for your Function App
  • Azure Storage: You can choose your existing storage account or If you don’t have an existing one then click on the New button to create a new Storage account.

Now click on the Create button.

Publish Azure Functions Time Trigger From Visual Studio 2019

Now click on the Publish button from the below window to Publish the Azure Function

Publish Azure Functions Time Trigger using Visual Studio 2019

On the next pop up, click on the Yes button to update the Azure Function version

How to Publish Azure Functions Time Trigger using Visual Studio 2019

Now your Azure Function will get publish successfully. Next step is we will verify if it is actually published successfully or not and then We will test if the Azure timer function is working or not.

To check all these things, you need to navigate to the Azure Function App that you have published just now.

Log in to the Azure Portal and search for the App services and then click on the search result. You will find your Azure function App in the list of app services. Click on your Azure Function App. Then, As shown below, On the Azure Function App page, click on the Functions from the left navigation

How to deploy Azure Functions Time Trigger using Visual Studio 2019

On the Azure Function page, click on the Code + Test link from the left navigation and then to test the Azure Function, if it is working fine as expected, click on the Test/Run button.

How to deploy Azure Functions Time Trigger from Visual Studio

The next step is click on the Run button from the below window

How to publish Azure Functions Time Trigger from Visual Studio

Now you can see below we got the expected response code i.e 202 Accepted.

azure function timer trigger visual studio

Now to see if the function executed on every 5 minutes or not, Select the log as Information, You can able to see the function execution time on each 5 minutes

Deploy Azure Functions Time Trigger from Visual Studio 2017

Create Blob Trigger Azure Function In Visual Studio

Well, Above we discussed, How To Create And Deploy Azure Functions Time Trigger From Visual Studio 2019. Now let’s discuss How to Create Blob Trigger Azure Function In Visual Studio.

Prerequisites will be the same as Timer trigger Azure Function as mention above. So let’s start with the creation of the Blob trigger Azure Function using Visual Studio 2019.

Well, now we can start the development activities with all the Prerequisites needed. Let’s start creation of the Azure Function Project.

Open the Visual Studio 2019 and On the Create a new project window, click on the Create a New Project button. You need to select the Azure Functions template and then click on the Next button.

Create Blob Trigger Azure Function In Visual Studio

Provide the Project name, and choose a location for your project where you want to store your project from the below window and then click on the Create button.

Create Blob Trigger Azure Function In Visual Studio 2017

Select the trigger template as Blob trigger and Storage Account (AzureWebJobsStorage) as Storage Emulator and then the next is Provide a name for the connection string setting and then click on the Create button

How to Create Blob Trigger Azure Function In Visual Studio 2019

Now if you will see below, the project created successfully with out any issue

Configure Blob Trigger Azure Function In Visual Studio

The below is the code for the Azure Function code that got created

public static class Function1
    {
        [FunctionName("Function1")]
        public static void Run([BlobTrigger("samples-workitems/{name}", Connection = "MyDemoConnection")]Stream myBlob, string name, ILogger log)
        {
            log.LogInformation($"C# Blob trigger function Processed blob\n Name:{name} \n Size: {myBlob.Length} Bytes");
        }
    }

The next step is we should make sure that the connection string is there with the same name that we provide before step i.e “MyDemoConnection” with the key-value pair in the local.settings.json file. Open the local.settings.json file.

So the key here is “MyDemoConnection” and we need the value for this, to get this value we need to log in to the Azure Portal. Log in to the Azure Portal, then navigate to the storage account and then click on the “Access keys” under settings from the left navigation. As highlighted below, You need to copy the connection string.

Creating an Azure function that triggers when a blob is uploaded

Now open your local.settings.json file and do the below changes, where you need to add the key and value pair for your Connection String. The local.settings.json file should look like below now.

{
    "IsEncrypted": false,
  "Values": {
    "AzureWebJobsStorage": "UseDevelopmentStorage=true",
    "FUNCTIONS_WORKER_RUNTIME": "dotnet",
    "MyDemoConnection": "DefaultEndpointsProtocol=https;AccountName=mynewstoragedemo;AccountKey=pNWgITmf33ROgS1ixyUAQ4fIQIhaqBUWQjwI79/PjLy9zRoqEsvOQ7fn1gu41sj+dQ9eCHA/sDew8/OhDMfI9w==;EndpointSuffix=core.windows.net"
  }
}
Develop Blob Trigger Azure Function In Visual Studio

Now your function to work, it needs someplace to write the information. So you can write the information into the “AzureWebJobsStorage”.

{
    "IsEncrypted": false,
  "Values": {
    "AzureWebJobsStorage": "DefaultEndpointsProtocol=https;AccountName=mynewstoragedemo;AccountKey=pNWgITmf33ROgS1ixyUAQ4fIQIhaqBUWQjwI79/PjLy9zRoqEsvOQ7fn1gu41sj+dQ9eCHA/sDew8/OhDMfI9w==;EndpointSuffix=core.windows.net",
    "FUNCTIONS_WORKER_RUNTIME": "dotnet",

    "MyDemoConnection": "DefaultEndpointsProtocol=https;AccountName=mynewstoragedemo;AccountKey=pNWgITmf33ROgS1ixyUAQ4fIQIhaqBUWQjwI79/PjLy9zRoqEsvOQ7fn1gu41sj+dQ9eCHA/sDew8/OhDMfI9w==;EndpointSuffix=core.windows.net"
  }
}

You can see like below

How to Develop Blob Trigger Azure Function In Visual Studio

To upload a file, to the storage container, you can do that using the Azure Storage Explorer

Open the Azure Storage Explorer, click on the Connect to Azure Storage button from the left navigation as highlighted below. select the Use a connection string option and then click on the Next button.

How to Create Blob Trigger Azure Function In Visual Studio

You can paste the same connection string as above. Display name will populate automatically, once you will put the value of the connection string and then click on the Next button.

Develop a Blob Trigger Azure Function In Visual Studio

Now it will show you the connection Summary details with all the information like below. Now click on the Connect button

How to Develop a Blob Trigger Azure Function In Visual Studio 2019

You can able to see all the connection details and storage account details, Expand the

How to Develop a Blob Trigger Azure Function In Visual Studio 2017

Provide the container name as samples-workitems which we have mention above as the path value. Click on the Upload and upload a file in your container. Then again you can run the Azure Function App again.

How to Develop a Blob Trigger Azure Function In Visual Studio 2017

I have already uploaded one file in the samples-workitems container. Now if you will run (F5) the application, you can able to see the expected OutPut

How to Develop Blob Trigger Azure Function In Visual Studio 2019

Deploy Blob Trigger Azure Function From Visual Studio 2019

Now To deploy the Blob Trigger Azure Function From Visual Studio 2019, You need to follow the below steps

Right click on the Project name and click on the Publish option.

Deploy Blob Trigger Azure Function From Visual Studio 2019

Choose the Azure Functions Consumption Plan and then select the Create New option and then click on the Create Profile button.

How to Deploy Blob Trigger Azure Function From Visual Studio 2019

On the App Service window, Provide the below details

  • Name: You need to provide the name for the Function App
  • Subscription: Choose your correct Azure subscription
  • Resource group: You can click on the New button to create a new Resource Group or You can choose your existing resource group.
  • Location: Choose your Function App location
  • Azure Storage: If you don’t have an existing storage account then click on the New button to create a new Storage account else You can choose your existing storage account.

Now click on the Create button.

How to Deploy Blob Trigger Azure Function From Visual Studio 2017

Now you can able to see the Azure Function App created successfully without any issue. Now click on the Publish button.

How to Deploy Blob Trigger Azure Function From Visual Studio

Now, log in to the Azure Portal and navigate to the Azure Function App that you have created from the Visual Studio above, and on the Function App window, click on the Functions option from the left navigation. Then you will see the Azure Functions that we have created from the visual studio. Click on the Function and on the Function page, click on the Code + Test link and then click on the Test/Run button.

How to publish Blob Trigger Azure Function From Visual Studio

Click on the Run button from the below window.

How to publish Blob Trigger Azure Function From Visual Studio 2019

You can able to see We got the correct response code i.e 202 Accepted.

How to publish Blob Trigger Azure Function From Visual Studio 2017

You may also like following the below articles

Wrapping Up

Well, in this article we have discussed, How To Create Azure Functions Time Trigger From Visual Studio 2019, How To Schedule Azure Functions, How To Deploy Azure Functions Time Trigger From Visual Studio 2019 and we also discussed Create Blob Trigger Azure Function In Visual Studio and Deploy Blob Trigger Azure Function From Visual Studio 2019. Hope you have enjoyed this article !!!