Chapter 1: Beginning Azure Function Apps PDF

Summary

This document provides an introduction to Azure serverless architecture, focusing on Azure Functions, Logic Apps, Event Grid, and Cosmos DB, along with real-world scenarios. It also explores the need for serverless technologies and the benefits they offer.

Full Transcript

# Chapter 1: Beginning Azure Function Apps ## Introduction - This chapter will cover Azure serverless architecture, why it should be used, and real-world use cases. - It will also cover Azure serverless services like Azure Functions, Logic Apps, Event Grid, and Cosmos DB. - The chapter will then d...

# Chapter 1: Beginning Azure Function Apps ## Introduction - This chapter will cover Azure serverless architecture, why it should be used, and real-world use cases. - It will also cover Azure serverless services like Azure Functions, Logic Apps, Event Grid, and Cosmos DB. - The chapter will then discuss on-premise, laas, PaaS, and serverless application paradigms. - It will cover triggers and bindings. - Finally, the chapter will cover Azure function pricing plans. ## Objective - Understand Azure serverless architecture and application deployment paradigms. - Understand Azure Functions, their features, and integration with other Azure services. - Understand language support for functions in different runtime versions. - Understand triggers and bindings. - Understand Azure function pricing plans. ## Azure Serverless Architecture - Serverless architecture focuses on developing applications without worrying about infrastructure management. - Benefits include: - Faster development. - No need to manage operating systems, infrastructure, or configurations. - Focus on function implementation. - Invisible server management and capacity planning. - Event-driven. - Real-world scenarios where Azure serverless architecture is used: - Single Page Applications (SPA). - Web applications. - Mobile applications. - IoT devices. - Real-Time file processing. - Real-Time stream processing. - Automating tasks. - SaaS integration. ## What is Azure Serverless Architecture? - Focuses on developing applications faster without worrying about infrastructure. - Doesn't require managing servers, operating systems, infrastructure, or configurations. - Focuses on function implementation only. - Invisible server management and capacity planning. - Event-driven. ## Why Serverless Architecture? - Build apps faster using serverless functions. - No need to manage server or infrastructure or administrative tasks. - Focus on function implementation and business logic only. - Applications can be scaled on demand. - Applications have high availability. - Pay-as-you-go billing based on the number of resources consumed or the time code is running. - Create modern applications with real-time triggers and bindings. - Integrate Azure services. - Work with intelligent services such as Azure machine learning and cognitive services. ## Real-world Case Studies of Serverless Applications - **Single Page Application (SPA)**: SPA dynamically loads content to the page and the app uses an Azure Function to host the site and pages. - **Web Application Backend**: Creates a serverless backend for a web application to process a queue, write output to a database, or store information in CosmosDB. - **Mobile Application Backend**: A mobile application can use a backend to save data, send email notifications, or process high-intensity tasks. ## Azure Functions - Invoked by a trigger, such as an http endpoint or a timer. - Integrated with other Azure services such as queues, storages, databases, or Logic Apps. - Three Versions: - **Version 1**: Supported by .NET full framework. - **Version 2**: Supported by .NET Core. - **Version 3**: Supported by .NET Core 3.1 onwards. - Supported languages: C#, F#, JavaScript, Java, Python, PHP, TypeScript, batch, bash, or PowerShell. - Can be written in the Azure portal or an IDE such as Visual Studio or Visual Studio Code. ## Logic Apps - Serverless platform to build automated workflows. - Integrates applications and data between cloud services or on-premises systems. - Built using a visual designer in the Azure portal or an existing trigger template. - Triggers are events or timers. - Integrates with Azure services including databases, storages, queues, event grids, Outlook, SharePoint lists, social media apps, and function apps. - Has a workflow run history for troubleshooting. ## Event Grid - Event-based applications based on publisher-subscriber architecture. - Publish and consume events from any platform. - Supports events from blob storage and other Azure resources. - Supports millions of events and large-scale event routing and real-time delivery. - Integrates with Azure and on-premises services. - Uses a push mechanism to deliver events to subscribers. ## Azure Functions - **Triggers** define how a function is invoked. - **Bindings** connect other resources to a function. - Bindings can be input or output. ## Triggers - HttpTrigger: Invokes a function with an http request. - TimerTrigger: Runs a function on a schedule. - CosmosDBTrigger: Listens for inserts and updates in Cosmos DB and provides the data to the function. - BlobTrigger: Starts when a new or updated blob is detected and provides blob content to the function. - QueueTrigger: Starts when a new item is received in a queue and provides the item to the function. - EventGridTrigger: Watches for changes in event publishers and notifies about new events. - EventHubTrigger: Responds to an event sent to the event hub. - ServiceBusTrigger: Responds to messages from a service bus queue or topic. - GraphAPITrigger: Supports Microsoft Graph events. - NotificationHubTrigger: Sends push notifications to devices. ## Bindings - Azure Storage: - Blob storage input binding: Reads blobs and passes them to the function. - Blob storage output binding: Writes to blobs. - Queue storage output binding: Writes a message to a queue. - Table storage: - Table storage input binding: Reads a table in an Azure storage account (versions 1 and 2). - Table storage output binding: Writes to a table in an Azure storage account (versions 1 and 2). - CosmosDB: - CosmosDB input binding: Retrieves documents from Cosmos DB using the SQL API. - CosmosDB output binding: Writes a new document to Cosmos DB using the SQL API. - Event Grid, Event Hub, and Mobile Apps do not support input bindings. - Http and Webhook output binding: Responds to an http request and customizes the response. - Microsoft Graph: - Microsoft Graph input binding: Reads the content of an Excel table, OneDrive files, graph events, and auth tokens. - Microsoft Graph output binding: Modifies the content of an Excel table, OneDrive files, or sends an email through Outlook. - Service Bus: - Service Bus output binding: Sends messages to a queue or a topic. - SignalR: - SignalR input binding: Adds real-time capabilities to an application. - SignalR output binding: Broadcasts messages to all connected clients. - Twilio: - Twilio output binding: Sends messages to a user through Twilio API. - Timer: Does not support input or output bindings. - Table Storage: Does not support trigger bindings. ## Types of Applications using Azure Functions - **Serverless Web Applications:** Process online orders or user activities and store data in a database using a queue and a function that sends a notification to a user. - **Serverless Mobile Backend**: Processes requests from a mobile app, saves the output to a database, and sends a notification to a user. - **Timer-based Processing**: Processes data from a database on a schedule. - **Real-Time File Processing**: Processes patient records, sends them through OCR detection, and saves the result to a SQL database. The Azure function can be used to decode a PDF file, send it to a cognitive service for OCR detection, and save results to a database. - **Real-Time Stream Processing**: Processes data from various devices, stores it in an event hub, and uses a function to process and generate a dashboard for visualization. - **Real-Time Bot Processing**: Processes conversations from chat platforms and provides responses in real time. ## Pricing in Azure Functions - **Consumption Plan**: Azure provides the computational resources a function needs, and you pay only for the time that your function runs. - **App Service Plan**: You can run your functions in the same app service plan as web applications. ## Function Scaling - **Consumption Plan**: Azure function host scales dynamically based on the number of requests. - **App Service Plan**: The function runs on a dedicated Azure virtual machine in the free, basic, standard, and premium levels. ## Billing - **Consumption Plan**: Based on the number of executions, execution time, and memory. - **App Service Plan**: Hourly charge on resources other than the free tier. ## When to use App Service Plan? - When your function app needs more CPU and memory than the consumption plan provides. - When your function app runs continuously. - When your function app needs to run longer than the maximum execution time allowed by the consumption plan. - When you need a larger VM size or VPN connection. ## QueueTrigger in Visual Studio Code - **Prerequisites**: - Install Visual Studio Code. - Install Azure Functions extension for Visual Studio Code. - **Steps:** - Create a new project. - Select .NET Standard Runtime. - Select QueueTrigger template. - Provide a name for the function. - Choose a namespace. - Configure local.settings.json file. - Sign in to Azure or create a free account. - Select a storage account. - Provide a queue name. - Add a storage connection string value to local.settings.json file. - Create a queue in the storage account and add a message. - Run the application and verify that a new function has been created. ## Deploying QueueTrigger - Deploy the function app using Visual Studio Code. - Select a subscription and either use an existing function app or create a new one. - Select a function app name like MyFirstQueue Trigger. - The function will be created in the default Azure region (westus). ## QueueTrigger Function - The Azure function will monitor the queue for messages. - When a new message is added to the queue, the function will be triggered and the message will be passed to the function. ## Source Codes - Timer trigger function built using Visual Studio timer trigger function: https://github.com/hansamaligamage/timertriggerfunction - Queue trigger function built using Visual Studio Code queuetriggerfunction: https://github.com/hansamaligamage/queuetriggerfunction

Use Quizgecko on...
Browser
Browser