Yusuf Elnady Logo
Back to Notes

Microsoft Azure

Last updated: 1/25/2026

Microsoft Azure

  • Microsoft Azure is Microsoft’s cloud platform, including Infrastructure-as-a-Service (IaaS), Platform-as-a-Service (PaaS), and Software-as-a-Service (SaaS) solutions.

Azure Resource Group

  • A resource group is a virtual file/container that holds related Azure resources/services.
  • Resource groups help you to organize your Azure resources and make them easier to manage.
  • You can deploy, update, and delete all of the resources in a resource group as a group. You can also assign permissions to resource groups, which makes it easier to control who has access to your resources.
  • A resource group can contain one or more Azure resources, such as virtual machines, storage accounts, databases, web apps, function apps and more.
  • The resources within a resource group should have a similar lifecycle, and you can manage them together as a group.
    • For example, you might create a resource group for a web application, which would include the web app itself, as well as any related resources such as databases, storage accounts, and virtual networks.
  • You can find a list of all resources you have inside your Azure Subscription at: https://portal.azure.com/#view/HubsExtension/BrowseResourceGroups
  • When you open each of the resources inside your Resource Group, you can easily delete it.
  • When you open a resource group —> Overview —> You will see all resources created for your group:
    • Azure Machine Learning Workspace (I used it)
    • Web App (I used it)
    • Azure OpenAI Service (I used it)
    • Virtual Machine (I used it)
    • Azure Functions (I used it)
    • App Service Plan (I used it)
    • API App
    • Mobile App Backend
    • Azure Kubernetes Services (AKS)
    • Container Registry
    • Network Interface
    • SSH Key
    • Disk
    • Virtual Network
    • Application Insights
    • Key Vault
    • Storage Account
    • Network Security Group
    • Public IP address
    • Application Gateway
    • Data Factory
    • Active Directory (AD)
https://azure.microsoft.com/en-us/products
https://azure.microsoft.com/en-us/products
💡
It's worth noting that a resource can belong to only one resource group, but a resource group can contain resources from different Azure regions.
💡
Access all resources inside my subscription: https://portal.azure.com/#view/HubsExtension/BrowseAll

Examples of Using Resource Groups:

Here are some examples of how you might use Azure resource groups:

  • Web Application Project: You might create a resource group for a web application, which would include the web app itself, as well as any related resources such as databases, storage accounts, and virtual networks.
  • API Project: You might create a resource group for an API, which would include the API itself, as well as any related resources such as databases, storage accounts, and API Management policies.
  • Mobile App: You might create a resource group for a mobile app, which would include the back end of the mobile app, as well as any related resources such as databases, storage accounts, and Azure Notification Hubs.
  • Development Environment: You might create a resource group for a development environment, which would include all of the resources that you need to develop and test your applications, such as virtual machines, databases, and storage accounts.
  • Production Environment: You might create a resource group for a production environment, which would include all of the resources that you need to run your applications in production, such as web apps, databases, and load balancers.

What is the cost of my Resource Group?


Azure App Services

App Service is a fully managed platform as a service (PaaS) offering for developers to build, deploy, and scale [1] web applications, [2] REST APIs, [3] mobile backends, and [4] Function Apps.

  • It offers auto-scaling and high availability, supports both Windows and Linux, and enables automated deployments from GitHub, Azure DevOps, or any Git repo.
  • You can host your apps in the cloud and have Azure take care of the infrastructure.
  • It supports a variety of programming languages, including .NET, .NET Core, Java, Ruby, Node.js, PHP, and Python.
  • Managed Platform / Environment means you can focus on your code and application logic without worrying about the underlying infrastructure.
  • There are several types of Azure App Services:
    1. Web Apps: These are used to host websites and web applications.
      • Example: A company website
      • Description: Azure App Service is commonly used for hosting websites. You can deploy your HTML, CSS, and JavaScript files, as well as server-side code using languages like ASP.NET, PHP, or Node.js.
      • This allows you to build and host responsive, scalable, and secure web applications.
      • Link: https://azure.microsoft.com/en-us/products/app-service/web
    2. API Apps: These provide a platform for hosting RESTful APIs.
      • Example: A weather data API
      • Description: You can use Azure App Service to create and deploy RESTful APIs. These APIs can be consumed by various client applications, such as mobile apps, web apps, or other services, to provide data and functionality over HTTP.
      • Link: https://azure.microsoft.com/en-us/products/app-service/api
    3. Mobile App Backends: These offer a platform for building mobile app backends, providing features like data storage, push notifications, and integration with social media accounts.
      • Example: A mobile app backend for a social networking app
      • Description: Azure App Service is well-suited for building the backends of mobile applications. It provides features like authentication, push notifications, and data storage that are crucial for mobile app development.
      • This allows you to focus on the frontend of your app while Azure handles the backend services.
      • Link: https://azure.microsoft.com/en-us/products/app-service/mobile
    4. Function Apps: These let you develop serverless applications where your code is event-driven and can scale up and down automatically.
      • Example: A serverless function to process uploaded images
      • Description: It allows you to run event-driven, serverless compute code without managing infrastructure. You can create small, single-purpose functions that execute in response to various triggers, such as HTTP requests, message queues, or timers.
      • This is ideal for tasks like image processing, data integration, or automation.
      • Link: https://azure.microsoft.com/en-us/products/functions
    5. Logic Apps: A cloud platform where you can create and run automated workflows with little to no code. By using the visual designer and selecting from prebuilt operations, you can quickly build a workflow that integrates and manages your apps, data, services, and systems.
      • Example: An automated workflow for processing customer orders: Automatically creates a new customer account in a CRM system when a new order is placed in an e-commerce store.
      • Example 2: A workflow that automatically sends a notification to a team when a new bug is reported in a bug-tracking system.
      • Description: Azure Logic Apps is a serverless, visual workflow automation tool that allows you to create workflows integrating various services and applications. While not strictly an App Service type, you can use Logic Apps in conjunction with Azure App Service to automate business processes and orchestrate actions across different services.
      • Link: https://azure.microsoft.com/en-us/products/logic-apps
      • Note that Azure Logic Apps (Azure Echo System) is similar to Microsoft Power Automate (Microsoft 365). Power Automate is user-friendly. Logic Apps is lower level and more for developers for richer services.
💡
Azure App Services also offers additional features, such as security, load balancing, autoscaling, and automated management.
💡
You can also use it with GitHub, BitBucket, Docker Hub, or Azure Container Registry for continuous deployment.

Specialized App Services

In addition to the core App Service types I mentioned earlier (Web Apps, API Apps, Mobile App Backends, Function Apps, and Logic Apps), Azure also offers some specialized App Services designed for specific use cases.

  1. Azure Static Web Apps: This service is designed for hosting static web applications and single-page apps. It integrates with GitHub or Azure DevOps for automatic deployment, and it supports serverless APIs.
  2. Azure SignalR Service: SignalR is a real-time messaging and communication service. The Azure SignalR Service is a managed service that allows you to build real-time web applications, including features like chat applications, live dashboards, and online gaming.
  3. Azure Front Door: While not a traditional App Service, Azure Front Door is often used in conjunction with web apps. It's a global, scalable, and secure content delivery network (CDN) service that improves the availability and performance of web applications.
  4. Container Apps: Deploy and manage containerized applications.
  5. Azure Spring Apps: Spring Apps are used to deploy and manage Spring Boot applications.
  6. WordPress Apps: WordPress Apps are used to deploy and manage WordPress websites.
  7. Custom Domain Apps: Custom Domain Apps are used to host web applications on a custom domain.

Azure Web Apps

Web Apps are a type of App Service that is specifically designed for hosting web applications.

  • They provide a fully managed environment for running web apps, including features such as:
    • Automatic scaling
    • Load balancing
    • SSL/TLS certificates
    • HTTP/2 support
    • Custom domains
    • Deployment slots
    • Diagnostics and logging

Connection between App Services and Web Apps:

FeatureApp ServiceApp Webs
DefinitionA fully managed platform as a service (PaaS) offering for developers to build, deploy, and scale web applications, REST APIs, and mobile back ends.A type of App Service that is specifically designed for hosting web applications.
FeaturesAutomatic scaling, load balancing, SSL/TLS certificates, HTTP/2 support, custom domains, deployment slots, diagnostics and logging.Same as App Service, plus additional features such as support for ASP.NET, ASP.NET Core, Java, Node.js, PHP, and Python.
Use casesHosting web applications, REST APIs, and mobile back ends.Hosting web applications.

Important to Study From: How to Deploy Web Apps to the Cloud with Flask & Azure (It Worked when I followed it)

This video changed a lot in my knowledge: LangChain on Microsoft Azure - ChatBot with Azure Web Service & Azure Cognitive Search (It Worked when I followed it) https://eightify.app/summary/computer-science-and-technology/langchain-on-azure-chatbot-cognitive-search

Instructions for Configuring and Deploying a Flask Web Application to Azure App Service

  • App Service uses the Gunicorn web server by default, which must be able to find your app object or wsgi.py folder. If needed, you can Customize the startup command.
  • For Flask, App Service looks for a file named application.py or app.py and starts Gunicorn as follows:
shell
# If application.py
gunicorn --bind=0.0.0.0 --timeout 600 
  • If your main app module is contained in a different file (ex: X.py) or you want to provide additional arguments to Gunicorn, you can customize the startup command.
  • To Change the Startup Command:
    1. Go to Web App Settings —> Configuration —> Startup Command
    2. Write the new Startup Command such gunicorn --bind=0.0.0.0 --timeout 600 --chdir folder_name X_Production:app, OR
    3. Write the name of the file (startup.txt) that will contain the Custom Startup Command.
    • For example, inside startup.txt, we write gunicorn --bind=0.0.0.0 --timeout 600 --chdir folder_name X_Production:app
      • X_Production is the name of the Flask app object and folder_name is the folder where your application code is located.
      • app is the app name that we assign in our code at app = Flask(name)
  • To make your Flask application work well with Azure, you should modify your Flask application code slightly.
    python
    if __name__ == '__main__': # 
  • Important: To Push from (somewhere) my code to Azure Web App, it has to be hosted somewhere such as Github, BitBucket, Azure Repos, Local Git, …
    • In our case, we have Azure DevOps —> Project (Data Science) —> We need to create a new repo called “<repo_name>”, and will configure it inside Deployment Center
    • To clone from Azure DevOps, we need to click Clone —> Generate Credentials so we have a Password we can use.
    • Using Azure Repos, we don’t need to have complex GitHub Actions, it’s all done immediately for us
    • You need to go to the Deployment Center and wait until the commit says Success (Active), which could be about 5 minutes.
  • Important: To Configure Env Variables —> Web App —> Settings —> Configuration —> Application settings
  • We need also to prepare a requirements.txt file
    • The App Service deployment engine automatically activates a virtual environment and runs pip install -r requirements.txt
    python
    python-dotenv
    langchain
    
    • Problems:
      • I forgot to add gunicorn to the requirements.txt
      • I forgot to add openai to the requirements.txt
    • It's a good practice to include specific versions because library updates can sometimes introduce changes that might break your application or cause unexpected behavior.
    python
    pip install pipreqs 
    pipreqs /Path/To/Project 
    # This will add also the versions and only the libraries of my selected project

Working Example (AI Document Editing)

python
from langchain.chat_models import AzureChatOpenAI
from langchain.schema import HumanMessage, SystemMessage, ChatMessage
from langchain.callbacks import get_openai_callback
import tiktoken
import logging
import gunicorn

from flask import Flask
from flask_restful import Resource, Api, reqparse




app = Flask(__name__)
api = Api(app)


def count_tokens(text):
    encoding = tiktoken.encoding_for_model('gpt-4.1') # Define LLM Model Name
    return len(encoding.encode(text))

def edit_text(option, text):
    instruction_options = {
        "1": "Improve Writing: ",
        "2": "Fix Spelling & Grammer: ",
        "3": "Make Shorter: ",
        "4": "Make Longer: ",
        "5": "Simplify Language: ",
        "6a": "Change Tone to Professional: ",
        "6b": "Change Tone to Casual: ",
        "6c": "Change Tone to Straightforward: ",
        "6d": "Change Tone to Confident: ",
        "6e": "Change Tone to Friendly: ",
    }

    content = f"{instruction_options[option]}\n\n {text}"

		# The needed Env Variables of Azure OpenAI are defined in the configuration settings as mentioned before!
    gpt_model = AzureChatOpenAI(deployment_name="ai-document-openai",model_name="gpt-4.1")
    
    with get_openai_callback() as cb:
        response = gpt_model(
            [
                HumanMessage(
                    content=content
                )
            ]
        )
    
    return response.content, round(cb.total_cost, 6)



# Define the API resource
class AIDocumentEditing(Resource):
    def post(self):
        try:
            # Parse the request data
            parser = reqparse.RequestParser()
            parser.add_argument('option', type=str, required=True) # 1- improve writing # 2- Fix Spelling & Grammer # 3- Make Shorter # 4- Make Longer # 5- Simplify Language # 6- Change Tone (a)
            parser.add_argument('text', type=str, required=True)
            args = parser.parse_args()

            # Extract option and text from the parsed data
            option = args['option']
            text = args['text']

            # Call LLM
            edited_text, cost = edit_text(option, text)

            # Create a response
            response = {
                'status': 'success',
                'message': 'Data processed successfully',
                'result': edited_text,
                'cost': cost
            }

            return response, 200

        except Exception as e:
            response = {
                'status': 'error',
                'message': str(e)
            }
            return response, 400

class CountTokens(Resource):
    def post(self):
        try:
            # Parse the request data
            parser = reqparse.RequestParser()
            parser.add_argument('text', type=str, required=True)
            args = parser.parse_args()

            text = args['text']

            # Call Tokenizer
            result = str(count_tokens(text))

            # Create a response
            response = {
                'status': 'success',
                'message': 'Finished successfully',
                'result': result
            }

            return response, 200

        except Exception as e:
            response = {
                'status': 'error',
                'message': str(e)
            }
            return response, 400
            
# Add the resource to the API
api.add_resource(AIDocumentEditing, '/edit')
api.add_resource(CountTokens, '/counttokens')

if __name__ == '__main__':
    logging.info("Flask App Started")
    app.run(host="0.0.0.0",port=8000)

Azure Functions

Azure Function Apps

  • In Azure, a Function App is a serverless computing service that allows you to run small pieces of code, called "functions," in response to events such as HTTP requests, timer events, and changes to data in Azure services or third-party services.
  • A Function App contains one or more functions, which are individual units of code that perform a specific task.
  • They are ideal for building microservices, background processing, and automation.
  • Function apps can be used for a variety of tasks, such as processing incoming data, creating reports, sending notifications, and integrating with other systems.
  • Functions are written in either C#, Java, JavaScript, PowerShell, and Python.
💡
Azure Functions is a good choice for applications that are event-driven, such as processing data from Azure Blob Storage or responding to HTTP requests.

Examples:

  • A function app that processes incoming customer orders and updates a database with the order details.
  • A function app that generates a daily report summarizing website traffic and sends it to stakeholders.
  • A function app that triggers a message to be sent to a user when a new item is added to a shopping cart.

When to use Azure Functions:

  • When you need to run code without having to provision or manage servers.
  • When you need to scale your application automatically based on demand.
  • When you need to pay only for the time that your code is running.
  • When you need to develop and deploy event-driven applications.

AWS has a similar service called AWS Lambda, which allows you to run code in response to events.

Azure Function Payment Plans

Azure Functions offers several pricing plans to meet different needs and usage scenarios. Here are the main payment plans available for Azure Functions:

  1. Consumption plan: This plan is suitable for applications with variable and unpredictable workloads. You only pay for the execution of your functions, based on the number of executions, execution time, and memory used. You are charged per 100ms of execution time and per GB-second of memory usage. There are no upfront costs or termination fees.
  2. Premium plan: This plan is designed for applications that require high memory and CPU resources or need to run for longer durations. You are charged for the number of vCPUs and GB of memory allocated to your functions. You can scale up or down to meet your application's needs, and you are only charged for the resources you use.
  3. Dedicated plan: This plan is suitable for applications that require a high degree of customization and control over the infrastructure. You can deploy your functions on dedicated infrastructure, such as virtual machines or Kubernetes clusters, and manage the environment yourself. You are charged for the resources you provision, and there are no limits on execution time or memory usage.

In addition to these plans, Azure Functions also offers a free tier with limited resources and usage, as well as a trial period for new customers to try out the service.

It's worth noting that the pricing for Azure Functions, like most cloud services, can be complex and depends on various factors, such as the region, execution time, memory usage, and data transfer. You should consult the Azure Functions pricing page or use the Azure Pricing Calculator to estimate your costs based on your specific needs.

Cost in Consumption Plan

In a Consumption plan, Azure Functions only charges you for the time your function code runs in response to a trigger, and for the memory used by the function while it's running.

If your function app is running but there are no triggers or events to activate your functions, then your functions are not running and you are not charged for any execution time or memory usage. However, you may still incur some minimal charges for storage and networking usage.

It's important to note that the Azure Functions in Consumption plan also offers a free grant of up to 1 million requests and 400,000 GB-s of resource consumption per month, which can help you stay within a free tier and not incur any charges for that month.

In summary, if your function app is running on a Consumption plan but no triggers are being fired, you should not be charged for any execution time or memory usage, but you may still incur some minimal charges for storage and networking usage.

Azure Functions are Serverless

  • Azure Functions are considered serverless because they allow you to run code without worrying about the underlying infrastructure.
  • With traditional server-based architectures, you need to provision, manage, and maintain servers to host your code. This can be time-consuming and costly, especially if you need to scale your application to handle increased traffic.
  • With Azure Functions, Microsoft takes care of all the infrastructure management for you. You don't need to worry about provisioning or managing servers, operating systems, or middleware. Azure Functions are built on top of a serverless compute service called Azure App Service, which abstracts away the underlying infrastructure and provides a fully managed hosting environment.
  • Azure Functions also offers a "pay-as-you-go" pricing model, where you only pay for the resources that you use when your functions are running. This can be more cost-effective than traditional server-based architectures, where you need to pay for servers even when they are idle.
In summary, Azure Functions are serverless because they provide a fully managed hosting environment and a pay-as-you-go pricing model, allowing you to run your code without worrying about the underlying infrastructure.


Microsoft Authentication Library (MSAL)

  • The Microsoft Authentication Library (MSAL) provides two classes to handle authentication: PublicClientApplication and ConfidentialClientApplication. The choice between these two classes depends on the type of client application you are building.
  • PublicClientApplication is used for client applications that run on user devices, such as web applications and mobile apps. These applications are referred to as public clients because they cannot guarantee the confidentiality of their secrets. Public clients use the OAuth 2.0 authorization code flow or implicit flow to obtain tokens.
  • ConfidentialClientApplication is used for client applications that run on a server, such as web APIs or command-line tools. These applications are referred to as confidential clients because they can guarantee the confidentiality of their secrets. Confidential clients use the OAuth 2.0 client credentials flow or the on-behalf-of flow to obtain tokens.
  • Here are some scenarios in which you might use each type of client application:
    • Use PublicClientApplication if you are building a web or mobile application that needs to access resources on behalf of a user. For example, if you are building a web application that accesses Microsoft Graph API to read a user's calendar events, you would use PublicClientApplication.
    • Use ConfidentialClientApplication if you are building a server-side application that needs to access resources on behalf of itself, without user interaction. For example, if you are building a web API that needs to access Microsoft Graph API to retrieve user data, you would use ConfidentialClientApplication.
    • In summary, you should use PublicClientApplication if you are building a public client that runs on user devices, and ConfidentialClientApplication if you are building a confidential client that runs on a server.