name Azure docs link for functions triggers
type link
action https://docs.microsoft.com/en-us/azure/azure-functions/functions-triggers-bindings?tabs=csharp
  • Small piece of code.
  • Function app is group of functions.
  • When creating a function app, you must create or link to a general-purposeAzure_Storage_Account that supports Blobs, Queue, and Table storage.

There are number of templates for functions and online IDE to write code for your function as well visual studio support. Triggers → When some action happens execute function, like when a row is added to a table. , some thing is added in a queue or on somesignalR message.

Function authorization level, one of three:

  1. Function
  2. Anonymous (take key and access level)
  3. Admin (need even higher authorization)

Coding

Online IDE: It needs to have a function.json which contains the authorization level: This can be used to very well send telegram updates, no server config required, just create a method and let it work :D

Code to return a text from HTTP call to server, index.js file

module.exports = async function (context, req) {
	context.log('JS HTTP trigger function processed a request.');
 
	const name = (req.query.name || (req.body && req.body.name));
	const responseMessage = name ? "Hello "+name : 'Pass a name in queryString';
// for blob storage
	context.bindings.outputBlob = name;
 
	context.res = {
		status: 200,
		body: responseMessage
	};
}
 

Get function URL:

Output: Real time logging here

Adding Blob Output Binding

  • Create a storage account.
  • Not to integrate go to integration tab and add output,
  • Create new storage account connection and in storage account create new container that you will give in path here.

  • Your function.json will automatically get modified for the outputBlob

  • to download the storage file, go to Generate SAS

  • and name is present there.

Timer Trigger Function

0***** → run every minute 01 → every minute on Monday 012 1 → every minute on Monday in Month of December. 0/5**** → every five minutes. #cron

module.exports = async function(context, myTimer) {
	var timeStamp = new Date().toISOString();
 
	if (myTimer.isPastDue) { 
		context.log('Running late')
	}
	context.log('JS timer trigger function ran', timeStamp);
}

Azure Durable Functions

  • Stateful
  • Could be long running/ multi step.
  • Can call other functions
  • Client - triggered the function
  • Orchestrator → Monitor bandwidth and traffic, contain code for chaining etc.
  • Activity → unit of work, like call an API, connect to DB.

Fan out/ Fan in pattern Asynchronous API pattern

  • Monitor patter → waiting for something to happen, not sure of time it will take. Like a listener.

npm install in function app

this will open it in visual studio code type editor

  • Create package.json file in the editor

Do npm install by Console

Create a Durable Function

Create a function with Durable Functions orchestrator template. myOrch/index.js

const df = require("durable-functions");
 
module.exports = df.orchestrator(function* (context) {
	const outputs = [];
	outputs.push(yield context.df.callActivity("Question", "How are you?"));
	outputs.push(yield context.df.callActivity("Question", "What is your name?"));
	return outputs;
})
  • For question activity create a function with “Durable Functions Activity”

  • Question/index.js

module.exports = async function (context) {
	return `Are you really asking me, ${context.bindings.questiontext}`;
}
  • Add delay to execution

npm install moment

myOrch/index.js

const moment = require('moment');

// add delay
const deadline = moment.utc(context.df.currentUtcDateTime).add(1, 'h');
yield context.df.createTimer(deadline.toDate()); // sleep for an hour/ hibernate 

Function Core Tools

Commands:

  • func
  • az Open cloud shell from here,

func (help) func init func new code .

Start the function and put the log details in output.txt file. & in the end means start async and return back to us. It will run in the background now.

func start &> ~/logout.txt func start &> ~/logout.txt & pkill func

func azure functionapp publish “name of function”

Visual studio

  • Select Azure function invisual_studio
  • In the created function, add new item > azure function
  • After this a modal will come up to select function type and key levels (among function, anonymous ..)
  • This will give login to azure option.
  • After this the functions you add here should be visible in azure dashboard as well. I guess once you build them.

Microsoft learn Exercises and Sandbox

I guess the sandbox has been removed, here is a link to docs to create a function, https://docs.microsoft.com/en-us/azure/azure-functions/functions-create-function-app-portal

Create function that calls other function

Durable functions activity A function that will run whenever an Activity is called by an orchestrator function.