Azure Functions - amitbhilagude/userfullinks GitHub Wiki

  1. Overview
    1. Run a small piece of code without worrying about infrastructure.
    2. Serverless Application
    3. Supports multiple langauges C#, Java,Javascript, Python, Powershell
    4. Pay per code run. e.g. Consumption plan pricing model
    5. Protect HTTP trigger function with OAuth by integrating with Azure AD etc.
    6. Support Stateful serverless architecture e.g. Durable function
    7. Function runtime is opensource and available at Github
  2. What can I do with the Functions
    1. HTTP: Run code based on HTTP requests
    2. Timer: Schedule code to run at predefined times
    3. Azure Cosmos DB: Process new and modified Azure Cosmos DB documents
    4. Blob storage: Process new and modified Azure Storage blobs
    5. Queue storage: Respond to Azure Storage queue messages
    6. Event Grid: Respond to Azure Event Grid events via subscriptions and filters
    7. Event Hub: Respond to high-volumes of Azure Event Hub events
    8. Service Bus Queue: Connect to other Azure or on-premises services by responding Service Bus queue messages
    9. Service Bus Topic: Connect other Azure services or on-premises services by responding to Service Bus topic messages
  3. Function Plans
    1. Consumption Plan: Pay for code run time. Billed on per second code execution. Execution is no of time function is executed and Executed time is function run time and memory in GB used. Consider a case where the amount of memory used by the function stays constant. In this case, calculating the cost is simple multiplication. For example, say that your function call consumed 0.5 GB for 3 seconds. Then the execution is 1 and execution cost is 0.5GB * 3s = 1.5 GB-seconds. Memory usage is rounded up to the nearest 128-MB bucket. When your process is using 160 MB, you're charged for 256 MB. It has free plan for every month upto 1 million executions time and 400K GB-Seconds. Then it will charge per GB and per million executions.
    2. Premium Plan: Keep prewarmed instanced and pay for them. Any additional resource require will pay based on their code run. Calcuated based on CPU duration and Memory.
    3. App Service Plan: Run your functions just like your web apps. If you use App Service for your other applications, your functions can run on the same plan at no additional cost.
    4. Additional charges will be required for http trigger as it internally uses another function which is called Proxy function. This function will be used to keep httpconnection live and it will be charged from the time it requested and until we got complete response.
    5. Execution time varies based on Plan. e.g. Consumption has default 5 mins and can be increased to 10 mins. Premium and app services has default 30 and can be increased to unlimited.
  4. Durable functions
    1. Durable functions are stateful function it is used to solve problem.
      1. Function has default timeout but durable function is used for long running queue.
      2. Function is stateles but it can used to maintain states between activity. This can be used for workflow scenarios.
    2. Durable function Visual Studio Template creates 3 functions
      1. Starter function: The entry function is used to be called HTTP endpoint or trigger etc, which calls the Orchestrator function.
      2. Orchestrator function: Which calls durable functions. It can maintain the state. It goes in sleep mode until durable function doesn't reply which also saves the cost.
    3. Extension of Azure functions which is stateful functions. It is good for some of the pattern. It has OrchestrationTrigger attributes which comes under Azure.WebJob.Extensions.Durable nuget package which gives IDurableOrchestrationContext object.It uses Durable Tasks Open source framework. It gives benefits for scenarios like workflow, state management, Multiple exception handling.
    4. Function chaining Pattern: We can call one function get the result and call another function in sequential way. Await here will make main function on sleep and we don't have charge for sleep time.
    5. Fan-in and Fan-Out pattern: This pattern basically we do by call function, put data into queue and use of http trigger. This will be managed by durable function in few lines of code.Where we add these into Task object and complete using Task.WhenAll.
    6. Async http call where we have orchestrator start and it return endpoint for status. which we can run to check the status. Function orchestrator is An orchestration is a collection of functions or steps, called actions in Logic Apps, that are executed to accomplish a complex task
    7. Monitoring
    8. Human Interaction: auto approval etc.
    9. Aggregrator
  5. Good comparison on automation process. Should we use Azure function, Power Automate, Logic Apps or WebJobs comparision 7. Durable Entity: It is durable function used to manage and update the state using IDurableEntityClient attribute. 8. Durable Http: Call HTTP API directly from Orchestration function.
  6. Durable Function Types
    1. Orchestrator Functions : It takes cared of executing activity functions which actions needs to executed.
    2. Activity Functions : Activity functions are the basic unit of work in a durable function orchestration. For example, you might create an orchestrator function to process an order. The tasks involve checking the inventory, charging the customer, and creating a shipment. Each task would be a separate activity function
    3. Entity Functions: Entity functions define operations for reading and updating small pieces of state. We often refer to these stateful entities as durable entities. Like orchestrator functions, entity functions are functions with a special trigger type, entity trigger. They can also be invoked from client functions or from orchestrator functions. Unlike orchestrator functions, entity functions do not have any specific code constraints. Entity functions also manage state explicitly rather than implicitly representing state via control flow.
    4. Client Functions:
  7. Function developer reference: Developer reference
  8. How to create function
    1. use [assembly: FunctionsStartup(typeof(class))] from Microsoft.Azure.Functions.Extensions.DependencyInjection for namespace.
    2. Inherit startup class public class Startup : FunctionsStartup. which will have multiple method. Configure is one of them for dependency injection 3.Create method which has FunctionName has attribute e.g. [FunctionName("GetAssignment")]
    3. FunctionsStartup is main attribute which is part of Microsoft.Azure.Functions.Extensions.DependencyInjection