Skip to content

Latest commit

 

History

History
255 lines (180 loc) · 16.2 KB

File metadata and controls

255 lines (180 loc) · 16.2 KB

Function App manual deployment - Overview

Costa Rica

GitHub Cloud2BR OSS - Learning Hub

Last updated: 2025-10-01


Function App Hosting Options

In the context of Azure Function Apps, a hosting option refers to the plan you choose to run your function app. This choice affects how your function app is scaled, the resources available to each function app instance, and the support for advanced functionalities like virtual network connectivity and container support.

Tip

  • Scale to Zero: Indicates whether the service can automatically scale down to zero instances when idle.
    • IDLE stands for:
      • I – Inactive
      • D – During
      • L – Low
      • E – Engagement
    • In other words, when the application is not actively handling requests or events (it's in a low-activity or paused state).
  • Scale Behavior: Describes how the service scales (e.g., event-driven, dedicated, or containerized).
  • Virtual Networking: Whether the service supports integration with virtual networks for secure communication.
  • Dedicated Compute & Reserved Cold Start: Availability of always-on compute to avoid cold starts and ensure low latency.
  • Max Scale Out (Instances): Maximum number of instances the service can scale out to.
  • Example AI Use Cases: Real-world scenarios where each plan excels.
Flex Consumption
Feature Description
Scale to Zero Yes
Scale Behavior Fast event-driven
Virtual Networking Optional
Dedicated Compute & Reserved Cold Start Optional (Always Ready)
Max Scale Out (Instances) 1000
Example AI Use Cases Real-time data processing for AI models, high-traffic AI-powered APIs, event-driven AI microservices. Ideal for fraud detection, real-time recommendations, NLP, and computer vision services.
Consumption
Feature Description
Scale to Zero Yes
Scale Behavior Event-driven
Virtual Networking Optional
Dedicated Compute & Reserved Cold Start No
Max Scale Out (Instances) 200
Example AI Use Cases Lightweight AI APIs, scheduled AI tasks, low-traffic AI event processing. Great for sentiment analysis, simple image recognition, and batch ML tasks.
Functions Premium
Feature Description
Scale to Zero No
Scale Behavior Event-driven with premium options
Virtual Networking Yes
Dedicated Compute & Reserved Cold Start Yes
Max Scale Out (Instances) 100
Example AI Use Cases Enterprise AI applications, low-latency AI APIs, VNet integration. Ideal for secure, high-performance AI services like customer support and analytics.
App Service
Feature Description
Scale to Zero No
Scale Behavior Dedicated VMs
Virtual Networking Yes
Dedicated Compute & Reserved Cold Start Yes
Max Scale Out (Instances) Varies
Example AI Use Cases AI-powered web applications, dedicated resources. Great for chatbots, personalized content, and intensive AI inference.
Container Apps Env.
Feature Description
Scale to Zero No
Scale Behavior Containerized microservices environment
Virtual Networking Yes
Dedicated Compute & Reserved Cold Start Yes
Max Scale Out (Instances) Varies
Example AI Use Cases AI microservices architecture, containerized AI workloads, complex AI workflows. Ideal for orchestrating AI services like image processing, text analysis, and real-time analytics.

Function App: Configure/Validate the Environment variables

Note

This example is using system-assigned managed identity to assign RBACs (Role-based Access Control).

  • Under Settings, go to Environment variables. And + Add the following variables:

    • COSMOS_DB_ENDPOINT: Your Cosmos DB account endpoint 🡢 Review the existence of this, if not create it

    • COSMOS_DB_KEY: Your Cosmos DB account key 🡢 Review the existence of this, if not create it

    • COSMOS_DB_CONNECTION_STRING: Your Cosmos DB connection string 🡢 Review the existence of this, if not create it

    • invoicecontosostorage_STORAGE: Your Storage Account connection string 🡢 Review the existence of this, if not create it

    • FORM_RECOGNIZER_ENDPOINT: For example: https://<your-form-recognizer-endpoint>.cognitiveservices.azure.com/ 🡢 Review the existence of this, if not create it

    • FORM_RECOGNIZER_KEY: Your Documment Intelligence Key (Form Recognizer). 🡢

    • FUNCTIONS_EXTENSION_VERSION: ~4 🡢 Review the existence of this, if not create it

    • WEBSITE_RUN_FROM_PACKAGE: 1 🡢 Review the existence of this, if not create it

    • FUNCTIONS_WORKER_RUNTIME: python 🡢 Review the existence of this, if not create it

    • FUNCTIONS_NODE_BLOCK_ON_ENTRY_POINT_ERROR: true (This setting ensures that all entry point errors are visible in your application insights logs). 🡢 Review the existence of this, if not create it

      image image image image
    • Click on Apply to save your configuration.

      image

Function App: Develop the logic

  • You need to install VSCode

  • Install python from Microsoft store:

    image
  • Open VSCode, and install some extensions: python, and Azure Tools.

    image image
  • Click on the Azure icon, and sign in into your account. Allow the extension Azure Resources to sign in using Microsoft, it will open a browser window. After doing so, you will be able to see your subscription and resources.

    image
  • Under Workspace, click on Create Function Project, and choose a path in your local computer to develop your function.

    image
  • Choose the language, in this case is python:

    image
  • Select the model version, for this example let's use v2:

    image
  • For the python interpreter, let's use the one installed via Microsoft Store:

    image
  • Choose a template (e.g., Blob trigger) and configure it to trigger on new PDF uploads in your Blob container.

    image
  • Provide a function name, like BlobTriggerContosoPDFInvoicesDocIntelligence:

    image
  • Next, it will prompt you for the path of the blob container where you expect the function to be triggered after a file is uploaded. In this case is pdfinvoices as was previously created.

    image
  • Click on Create new local app settings, and then choose your subscription.

    image
  • Choose Azure Storage Account for remote storage, and select one. I'll be using the invoicecontosostorage.

    image
  • Then click on Open in the current window. You will see something like this:

    image
  • Now we need to update the function code to extract data from PDFs and store it in Cosmos DB, use this an example:

    1. PDF Upload: A PDF file is uploaded to the Azure Blob Storage container (pdfinvoices).
    2. Trigger Azure Function: The upload triggers the Azure Function BlobTriggerContosoPDFLayoutsDocIntelligence.
    3. Initialize Clients: Sets up connections to Azure Document Intelligence and Cosmos DB.
      • Initializes the DocumentAnalysisClient using the FORM_RECOGNIZER_ENDPOINT and FORM_RECOGNIZER_KEY environment variables.
      • Initializes the CosmosClient using Azure Active Directory (AAD) via DefaultAzureCredential.
    4. Read PDF from Blob Storage: Reads the PDF content from the blob into a byte stream.
    5. Analyze PDF: Uses Azure Document Intelligence to analyze the layout of the PDF.
      • Calls begin_analyze_document with the prebuilt-layout model.
      • Waits for the analysis to complete and retrieves the layout result.
    6. Extract Layout Data: Parses and structures the layout data from the analysis result.
      • Extracts lines, tables, and selection marks from each page.
      • Logs styles (e.g., handwritten content) and organizes data into a structured dictionary.
    7. Save Data to Cosmos DB: Saves the structured layout data to Cosmos DB.
      • Ensures the database (ContosoDBDocIntellig) and container (Layouts) exist or creates them.
      • Inserts or updates the layout data using upsert_item.
    8. Logging (Process and Errors): Logs each step of the process, including success messages and detailed error handling for debugging and monitoring.