Shanon Jackson
Shanon Jackson

Reputation: 6531

Timer based trigger - Testing locally

Trying to test CRON trigger function app locally but getting an error:

"The listener for function 'Functions.timer' was unable to start. Microsoft.Azure.WebJobs.Script: Could not create BlobServiceClient to obtain the BlobContainerClient using Connection: Storage."

local.settings.json

{
  "IsEncrypted": false,
  "Values": {
    "AzureWebJobsStorage": "",
    "FUNCTIONS_WORKER_RUNTIME": "node",
    "ConnectionStrings:BlobStorageAccount": "UseDevelopmentStorage=true"
  }
}

function.json

{
  "bindings": [
    {
      "schedule": "*/1 * * * *",
      "name": "reportScheduler",
      "type": "timerTrigger",
      "direction": "in"
    }
  ],
  "disabled": false
}

and index.js

const timer = async function(context, req) {
    context.log("=======PROCESSED=======");
    context.res = {
        // status: 200, /* Defaults to 200 */
        body: "HELLO WORLD",
    };
};

module.exports = timer;

Really struggling with the documentation specifically around these error messages and translating those into the required changes in local.settings.json

other information:

 npm i -g azure-functions-core-tools@3 --unsafe-perm true
 func start

Upvotes: 0

Views: 3121

Answers (2)

Nikhil Mishra
Nikhil Mishra

Reputation: 31

Follow these steps if you are working with VS Code https://learn.microsoft.com/en-in/azure/storage/common/storage-use-azurite?tabs=visual-studio-code

also add this in your local.settings.json

"AzureWebJobsStorage": "UseDevelopmentStorage=true"

Upvotes: 1

anon
anon

Reputation:

To run the azure functions (whatever the trigger type), need the azure functions core tools to be installed in your system. That you can install using npm command or executable file installation available in this documentation.

Note: To install the azure function core tools using npm command is: npm i -g azure-functions-core-tools@3 --unsafe-perm true and you have to run this command in integrated terminal of Visual Studio Code.

For Windows, integrated terminal of VS Code is PowerShell, here you can find the integrated terminal:

enter image description here

To Create and run the Timer Triggered Function, please refer this documentation for step by step procedure.

I have created the timer trigger JavaScript Azure Function and started to run the function using command func start, running successfully:

enter image description here

I set the CRON expression to every minute for running the function so it is showing the function runs at every minute in the above output console.

local.settings.json code:

{  
"IsEncrypted": false,  
"Values": {   
"AzureWebJobsStorage": "UseDevelopmentStorage=true",  
"FUNCTIONS_WORKER_RUNTIME": "node"  
}
}

And In your index.js:

const timer = async function(context, req

The req object refers to http request class so the req and res objects should be defined in function.json class like:

enter image description here

This documentation refers to Azure JavaScript Function Http Trigger.

Upvotes: 1

Related Questions